php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25314 ASCII mode doesn't work
Submitted: 2003-08-29 13:23 UTC Modified: 2004-01-06 00:32 UTC
From: phpbugs at brianmertens dot com Assigned:
Status: Closed Package: FTP related
PHP Version: 4.3.3 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbugs at brianmertens dot com
New email:
PHP Version: OS:

 

 [2003-08-29 13:23 UTC] phpbugs at brianmertens dot com
Description:
------------
This seems to be the same problem as 19036 (Closed) and 18162 (No Feedback).

Since neither is still open, I am filing a new report. I will provide any feedback required. I can test snaps if they are compiled for Windows.

Simply put, if I connect to a Unix (AIX 4.3) server and use ftp_get() to fetch a text file to a Windows machine with the FTP_ASCII option, the newlines are NOT converted to CR/LF pairs.

ftp_get( $conn, "file.txt", "file.txt", FTP_ASCII );

I have reproduced this with 4.2.x, 4.3.2 & 4.3.3.

(Note that ftp_systype() returns "UNKNOWN".)

Reproduce code:
---------------
$conn = ftp_connect( "server" );
ftp_login( $conn, "username", "password" );
ftp_get( $conn, "file.txt", "file.txt", FTP_ASCII );


Expected result:
----------------
Lines terminated with CR/LF pairs (x0D x0A).

Actual result:
--------------
Lines terminated with single x0A chars.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-07 19:57 UTC] sniper@php.net
This works as workaround:

<?php

$conn = ftp_connect( "server" );
ftp_login( $conn, "user", "pass" );
$fp = fopen('localfile.txt', 'wt');
ftp_fget( $conn, $fp, 'remotefile.txt", FTP_BINARY );

?>


 [2003-09-08 18:43 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Give snaps a chance to build a new version, but it should be all fixed now.
 [2004-01-05 16:09 UTC] kshadkhast at canwest dot com
I think this problem has not fixed yet.
I am using php4.3.4 and it got worth replacing \n to \r.
this code must be put in ftp_get function to fix this problem:

lastch = 0;
 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) {
	if (type == FTPTYPE_ASCII) {
		for (ptr = data->buf; rcvd; rcvd--, ptr++) {
			
			if ( *ptr == '\n')
				php_stream_putc(outstream, '\r');				
			
			if (lastch == '\r' && *ptr != '\n') 
				php_stream_write(outstream, '\r\n', 2);
						
			
			if (*ptr != '\r')
				php_stream_putc(outstream, *ptr);
			lastch = *ptr;
		}
	}
}

if (type == FTPTYPE_ASCII && lastch == '\r')
		php_stream_write(outstream, '\r\n', 2);
 [2004-01-06 00:32 UTC] pollita@php.net
Your suggested code would accomplish the opposite of desired behavior.  It would turn \r, \n, or \r\n into an explicit \r\n pair.  While this would function appropriately for Windows systems, Macintosh and Unix platforms would subsequently break.

The current code is designed to turn \r, \r\n, or \n into a straight \n character.  Because the output stream is opened with the "wt" mode, the file, when writen, will be output with \r\n for windows, \r for Mac, or \n for unix.

Your comment suggests that all \n characters are being translated to \r ?  Can you provide an example of this behavior using a publicly accessable webserver and a short, self-contained script?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 05 16:01:28 2024 UTC