Bug #70693 [NEW]: CURLOPT_FILE won't work with ftp handlers
| From: | marco dot marsala at live dot it | Date: | Mon, 12 Oct 2015 08:15:28 +0000 |
| Subject: | Bug #70693 [NEW]: CURLOPT_FILE won't work with ftp handlers | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196542@lists.php.net to get a copy of this message | ||
From: marco dot marsala at live dot it
Operating system: Windows
PHP version: 5.5.30
Package: cURL related
Bug Type: Bug
Bug description:CURLOPT_FILE won't work with ftp handlers
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
--
Edit bug report at https://bugs.php.net/bug.php?id=70693&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70693&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70693&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70693&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70693&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70693&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70693&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70693&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70693&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70693&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70693&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70693&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70693&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70693&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70693&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70693&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70693&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70693&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70693&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70693&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70693&r=mysqlcfg