php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47202 FTP fopen wrapper and # in file names
Submitted: 2009-01-23 15:22 UTC Modified: 2022-08-05 21:11 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: smlerman at gmail dot com Assigned:
Status: Re-Opened Package: FTP related
PHP Version: 5.2.8 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: smlerman at gmail dot com
New email:
PHP Version: OS:

 

 [2009-01-23 15:22 UTC] smlerman at gmail dot com
Description:
------------
It seems that the FTP fopen wrapper truncates file names when it encounters a pound sign (#). The FTP server's log shows a request for "file".

I have tried replacing the # with %23 (the result of urlencode), but the server sees that as a request for "file%231.txt".

Reproduce code:
---------------
// Use fopen wrapper
$data = file_get_contents("ftp://username:password@ftp.example.com/file
#1.txt");
var_dump(strlen($data));

// Use ftp_* functions
$conn = ftp_connect('ftp.example.com');
ftp_login($conn, 'username', 'password');
ftp_get($conn, 'C:\\test.txt', 'file#1.txt', FTP_BINARY);
var_dump(filesize('C:\\test.txt'));

Expected result:
----------------
int(7)
int(7)

Actual result:
--------------
Warning: file_get_contents(ftp://...@ftp.example.com/file#1.txt) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: FTP server reports 550 /file : The system cannot find the path specified. in...
int(0)
int(7)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-03 07:05 UTC] hradtke@php.net
The php_url_parse_ex function intentionally strips the # character from the filename.  I did some research and see that this was done to fix Bug #31705 (http://bugs.php.net/bug.php?id=31705).

From http://www.w3.org/Addressing/URL/4_URI_Recommentations.html :
The hash ("#", ASCII 23 hex) character is reserved as a delimiter to separate the URI of an object from a fragment identifier.

This behavior is intentional.


 [2012-06-16 13:54 UTC] langemeijer@php.net
-Status: Wont fix +Status: Re-Opened
 [2012-06-16 13:54 UTC] langemeijer@php.net
I was able to fix the problem for the ssh2 wrapper. I assume it can be fixed for 
ftp too. See bug #59794
 [2022-08-05 21:11 UTC] bukka@php.net
-Package: Streams related +Package: FTP related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 00:01:27 2024 UTC