From: ts dot serveroperations at wmdata dot com Operating system: Redhat Enterprise ES version 4 PHP version: 4.4.4 PHP Bug Type: FTP related Bug description: FTP function always transfers in binary mode
Description: ------------ The ftp function always transfer files in binary mode which results in textfiles being corrupted with no newlines. The configure line we used is ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --enable-module=so --enable-ftp We have not made any changes to php.ini. We tested on both the latest CVS snapshot and PHP 4.4.4 The code below expects a file named testfile.txt to be located in /var/www/html/ and a ftp server on localhost with user test, password test, address localhost and a folder named testdir. When we look in the logfile of the ftp server we see that the file actually was transferred in binary mode, we tried 2 different ftp servers with the same result. The ftp server and webserver are on the same machine (Linux Redhat), the php page is browsed from a windows XP computer and testfile.txt is downloaded and viewed in windows XP with notepad. This bug resembles Bug #19036 but this is between windows and linux which uses different newline characters. Therefore we must use ascii mode. Reproduce code: --------------- <?php // set up basic connection $ftp_server = "localhost"; $ftp_user_name = "test"; $ftp_user_pass = "test"; $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name"; } $source_file = "/var/www/html/testfile.txt"; $destination_file = "/testdir/testfile.txt"; // upload the file $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII); // check upload status if (!$upload) { echo "FTP upload has failed!"; } else { echo "Uploaded $source_file to $ftp_server as $destination_file"; } // close the FTP stream ftp_close($conn_id); ?> Expected result: ---------------- That the file was transferred in ascii mode and that the ftp server logfile would confirm that. Actual result: -------------- The file was transferred in binary mode. This was verified when opening the textfile and the newlines are gone, replaced by 3 squares. Also the ftp server logfile states that the transfer was in binary mode. This is true for both uploads and downloads. FTP server works as expected when using a regular ftp application e.g. flashfxp, filezilla etc. -- Edit bug report at http://bugs.php.net/?id=39583&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39583&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39583&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39583&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39583&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39583&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39583&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39583&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39583&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39583&r=support Expected behavior: http://bugs.php.net/fix.php?id=39583&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39583&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39583&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39583&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39583&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39583&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39583&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39583&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39583&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39583&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39583&r=mysqlcfg