php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48674 fopen() ftp wrapper and SIZE command
Submitted: 2009-06-24 11:15 UTC Modified: 2011-04-08 18:13 UTC
Votes:11
Avg. Score:4.4 ± 1.0
Reproduced:10 of 11 (90.9%)
Same Version:3 (30.0%)
Same OS:3 (30.0%)
From: bmorel at ssi dot fr Assigned:
Status: Open Package: Streams related
PHP Version: 5.2.10 OS: CentOS 5
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: bmorel at ssi dot fr
New email:
PHP Version: OS:

 

 [2009-06-24 11:15 UTC] bmorel at ssi dot fr
Description:
------------
(Request for reopening bug #35765)
Sorry to restart this thread more than 3 years later, but I'm facing the very same problem and cannot add a comment on a "won't fix" bug.

The problem concerns the fopen()'s ftp wrapper incorrectly relying on the ftp SIZE command to check whether a file is downloadable.

I do think that's not a correct behaviour.
For example I'm using a ftp server from a well-known affiliate marketing company, that's serving "virtual" files, that are not displayed in the ftp server as such, but downloadable by any ftp client I could try... except php's fopen wrapper.

The problem is that this server returns a "550 Not a plain file" error for a SIZE request. This is not a plain file, but it is perfectly downloadable.

The SIZE command is *not* standardized in RFC 959. It may be used by ftp clients, but only to try to get some information about the file.

Refusing to download a file due to a SIZE command failing is not RFC compliant, while the servers the previous bug reporter and I are using, are.

Reproduce code:
---------------
$fp = fopen("ftp://example.com/test.xml.gz", "rb");
var_dump($fp);

Expected result:
----------------
bool(true)

Actual result:
--------------
Warning: fopen(ftp://example.com/test.xml.gz) [function.fopen]: failed to open stream: FTP server reports 550 /test.xml.gz: not a plain file.
bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 18:13 UTC] jani@php.net
-Package: Feature/Change Request +Package: Streams related
 [2011-09-15 18:43 UTC] jesse at reltru dot com
Running into the same issue and would like to provide additional information



Ubuntu 10.04.3 LTS
PHP Version => 5.3.2-1ubuntu4.9



When using file_get_contents or fopen to connect to an FTP server that does not support the SIZE command the process will exit early

wget works correctly

tcpdump -vvvnA shows the following for file_get_contents

220 FTP
USER *****
331 Password required
PASS *****
230 User logged in
TYPE I
200 Type set to I, binar
SIZE /*****.***
500 Command not recogniz
221 You could at least s

Replaced username, pass and file with *'s but they are correct in the capture, after the 221 the process ends and throws an exception.

Capturing a wget shows the following:

220 FTP
USER *****
331 Password required
PASS *****
230 User logged in
SYST
500 Command not recogniz
PWD
257 Current directory is
TYPE I
200 Type set to I, binar
CWD /*****
250 Changed directory to
SIZE *****.***
500 Command not recogniz
PASV
227 Entering Passive Mod
RETR *****.***
150 Opening BINARY mode

Data is sent between FTP server and client successfully


Even though the attempt from wget to identify the file failed, it still attempts to download the file and works successfully
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC