php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43498 file_exists() on a proftpd server got SIZE not allowed in ASCII mode
Submitted: 2007-12-04 20:59 UTC Modified: 2008-01-08 19:10 UTC
From: vaneay at ifrance dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.2.5 OS: linux
Private report: No CVE-ID:
 [2007-12-04 20:59 UTC] vaneay at ifrance dot com
Description:
------------
on php 5.0 and up 
when trying to see if an ascii file exist on a ftp server tha follow RFC
we get the error "SIZE not allowed in ASCII mode"
example with ftp server proftpd 1.3.0 and up: 
$result = file_exists('ftp://user:pass@server.to.connect/dir/file.txt');
got always $result FALSE 
because in the server log the function file_exists() connect as the following : 

CONNECT
LOGIN 
PASS
CWD /dir/file.txt
SIZE /dir/file.txt
550 SIZE not allowed in ASCII mode
DISCONNECT

where a normal FTP client does : 

CONNECT
LOGIN 
PASS
CWD /dir/file.txt
TYPE I
SIZE /dir/file.txt
213 93 <- got Size here
DISCONNECT

Reproduce code:
---------------
$result = file_exists('ftp://user:pass@server.to.connect/dir/file.txt');

Expected result:
----------------
CONNECT
LOGIN 
PASS
CWD /dir/file.txt
TYPE I
SIZE /dir/file.txt
213 93 <- got Size here
DISCONNECT

Actual result:
--------------
CONNECT
LOGIN 
PASS
CWD /dir/file.txt
SIZE /dir/file.txt
550 SIZE not allowed in ASCII mode
DISCONNECT

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-07 04:16 UTC] crrodriguez at suse dot de
Right, this does not work:

php -r var_dump(file_exists("ftp://anonymous:foobar@rsync.proftpd.de/README.MIRRORS"));


other ftp servers do work though, however, the curl library (that I assume is right) does indeed send TYPE I before SIZE

try curl -v -I ftp://rsync.proftpd.de/README.MIRRORS

fix:

Index: ext/standard/ftp_fopen_wrapper.c
===================================================================
RCS file: /repository/php-src/ext/standard/ftp_fopen_wrapper.c,v
retrieving revision 1.85.2.4.2.4.2.2
diff -u -r1.85.2.4.2.4.2.2 ftp_fopen_wrapper.c
--- ext/standard/ftp_fopen_wrapper.c    30 Sep 2007 05:49:44 -0000      1.85.2.4.2.4.2.2
+++ ext/standard/ftp_fopen_wrapper.c    7 Dec 2007 04:15:59 -0000
@@ -770,7 +770,7 @@
        } else {
                ssb->sb.st_mode |= S_IFDIR;
        }
-
+       php_stream_write_string(stream, "TYPE I\r\n");
        php_stream_printf(stream TSRMLS_CC, "SIZE %s\r\n", (resource->path != NULL ? resource->path : "/"));
        result = GET_FTP_RESULT(stream);
        if (result < 200 || result > 299) {
 [2008-01-08 19:10 UTC] iliaa@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 21:01:56 2014 UTC