php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41056 FTP function converts text file into Windows Text file always in ASCII mode.
Submitted: 2007-04-11 18:19 UTC Modified: 2007-04-11 18:31 UTC
From: daniel at supercomm dot com Assigned:
Status: Not a bug Package: FTP related
PHP Version: 5.2.1 OS: Linux
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 !
Your email address:
MUST BE VALID
Solve the problem:
43 + 22 = ?
Subscribe to this entry?

 
 [2007-04-11 18:19 UTC] daniel at supercomm dot com
Description:
------------
FTP function converts text file into Windows Text file always while in ASCII mode.
ftp_fput() uploads a file assuming a Linux to Windows upload always.
when used in the opposite direction an extra 0x0D character is inserted
because the 0x0A character is always replaced with 0x0D+0x0A.


Reproduce code:
---------------
<?php
// usage: php test.php filename.txt username password server
// filename.txt must have crlf at the end of every line.
$conn_id = ftp_connect($argv[4]);
if ( @ftp_login($conn_id, $argv[2], $argv[3]) )
{
        $fhand = fopen($argv[1], 'rb');

        if ( $fhand )
        {
              ftp_delete($conn_id, $argv[1]);

	      $ftpmode = FTP_BINARY; // automatic ftp mode selection
              // Bug #39583  	FTP function always transfers in binary mode
              // Bug          FTP function converts text file into Windows Text file always while in ASCII mode.
              if ( eregi(".txt$",$argv[1]) ) $ftpmode = FTP_ASCII;

              // try to upload $file
              if (ftp_fput($conn_id, $argv[1], $fhand, $ftpmode, 0))
              {
                     echo "Successfully uploaded file\n";
              }
              else
                     echo "Found an error\n";
        }
}

?>

Expected result:
----------------
filename.txt at server repository...

In: CRLF
Out: CRCRLF

In: LF
Out: CRLF

Actual result:
--------------
none

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-11 18:31 UTC] tony2001@php.net
FTP functions do not change any data.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC