php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #859 Passive FTP (fopen wrapper) file transfer may fail with NcFTPd server
Submitted: 1998-10-20 09:38 UTC Modified: 1999-06-12 16:41 UTC
From: and at itaca dot it Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 3.0.5 OS: Digital Unix 3.2D
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: and at itaca dot it
New email:
PHP Version: OS:

 

 [1998-10-20 09:38 UTC] and at itaca dot it
Using any of the PHP functions to read a file via an FTP URL (fopen, readfile, etc) may fail if the remote FTP server
is operated by NcFTP Software's NcFTPd server (v.2.3.2 and below). Running PHP 3 as an Apache 1.3.3 module, the connection fails because the server doesn't accept the SIZE command while in ASCII file transfer mode (which is the default selected mode using the above combination of OS/HTTP server/PHP module). If the transfer mode is set to BINARY the command is understood and the file transfer takes place.

Since the php3_fopen_url_wrapper() function in fopen_wrappers.c file switches anyway to binary transfer mode before sending the PASV command, but after having sent the SIZE command, changing the order of FTP commands from:

  SIZE
  TYPE I
  PASV

to:

  TYPE I
  SIZE
  PASV

would cure the NcFTPd mis-functionality. This has already been successfully tested modifing the fopen_wrappers.c file in the following way:

...
  /* set the connection to be binary */
  SOCK_WRITE("TYPE I\n", *socketd);
  result = _php3_getftpresult(*socketd);
  if (result > 299 || result < 200) {
    free_url(resource);
    SOCK_FCLOSE(*socketd);
    *socketd = 0;
    return NULL;
  }

  /* find out the size of the file (verifying it exists) */
  SOCK_WRITE("SIZE ", *socketd);
  SOCK_WRITE(resource->path, *socketd);
  SOCK_WRITE("\n", *socketd);
...

---

Tested case

Having the URL ftp://ftp.server.mydomain/thefile in a readfile() function, with ftp.server.mydomain being
an NcFTPd FTP server:

ftp> ascii
200 Type okay.
ftp> size /thefile
502 Not implemented for TYPE A.
ftp> binary
200 Type okay.
ftp> size /thefile
213 481

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-12 16:41 UTC] jim at cvs dot php dot net
Fixed in CVS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 04:01:29 2024 UTC