php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70693 CURLOPT_FILE won't work with ftp handlers
Submitted: 2015-10-12 08:15 UTC Modified: 2019-03-26 17:29 UTC
From: marco dot marsala at live dot it Assigned:
Status: Verified Package: cURL related
PHP Version: 5.5.30 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
41 + 14 = ?
Subscribe to this entry?

 
 [2015-10-12 08:15 UTC] marco dot marsala at live dot it
Description:
------------
If CURLOPT_FILE option is specified, and the file is a ftp handler created by fopen, the resulting file on the ftp server is a zero-byte file.

Test script:
---------------
function save($dlPath, $path, &$filename = null) {
    // Allows overwriting of existing files on the remote FTP server
    $stream_options = array('ftp' => array('overwrite' => true));

    // Creates a stream context resource with the defined options
    $stream_context = stream_context_create($stream_options);

    log_msg("[info] Scarico $path ...");
    $headerBuff = tmpfile();
    $fileTarget = fopen($dlPath, 'w', false, $stream_context);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $path);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_WRITEHEADER, $headerBuff);
    curl_setopt($ch, CURLOPT_FILE, $fileTarget);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_PROXY, get_tor()); // instrada su proxy SOCKS5 o gateway Tor
    $f = _my_curl_exec($ch); // implementa le peculiarità
    
    rewind($headerBuff);
    $headers = stream_get_contents($headerBuff);
    if(preg_match('/^Content-Disposition: .*filename=("|\')?([^ ]+)("|\')?$/i', $headers, $matches)) {
        $filename = $matches[1];
        log_msg("[info] Nome del file scaricato: $filename ...");
    }

    fclose($fileTarget);
    fclose($headerBuff);
    return $f;
}

Expected result:
----------------
File size greater than zero

Actual result:
--------------
File size is 0 byte

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-26 16:27 UTC] mike@php.net
Probably fixable by upgrading internals to streams instead of stdio.

Related to Bug #76268
 [2019-03-26 17:29 UTC] mike@php.net
-Status: Open +Status: Verified
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC