Gaufrette
Gaufrette copied to clipboard
[ftp] problem with folders with spaces
ftp_rawlist() function returns empty result if there is a folder with space. You can use ftp_nlist() which does not have this problem.
I think ftp_nlist
could have the same issue, given that the PHP ftp_* functions don't escape their input.
I think the proper code would be to quote the directory name passed to ftp_rawlist
I tried to quote the directory name for ftp_rawlist
, it did not work. but ftp_nlist
works without the quotes. PHP 5.4.6
per php manual http://de3.php.net/manual/en/function.ftp-nlist.php
directory
The directory to be listed. This parameter can also include arguments, eg. ftp_nlist($conn_id, "-la /your/dir"); Note that this parameter isn't escaped so there may be some issues with filenames containing spaces and other characters.
so ftp_list
and ftp_rawlist
should have the same problems (or the manual is wrong)
could you try sorrounding the path with single quotes?
per https://bugs.php.net/bug.php?id=15231 it could also help to escape the space with \
I looked into php source code there are no additional handlers for commands. I suspect it depends on the implementation of commands ftp server. As a result
ftp_nlist()
solves my problem, but not solve the problem with spaces.
This lib looks great and probably fix the problem. We should maybe implement it. cc @l3l0
https://github.com/ngyuki/php-ftp-client
This library does not escape its argument either. So it suffers from the same issues than the PHP extension. the only difference is that it is written in PHP rather than C. The FTP extension is enabled by default in PHP, so avoiding it for an alternative which is not better is a bad idea IMO
// looks like this works
ftp_chdir($conn, 'directory with spaces');
$files = ftp_nlist($conn, '');
$files = ftp_rawlist($conn, ''); // also working for me
-- from http://php.net/manual/en/function.ftp-nlist.php
hi, get a list of directories and files within the folder with space in a name. you can try with below code in PHP.
Working solution
ftp_chdir($conn, $path);
$children = ftp_rawlist($conn,'-a .');
@php-dedicated-developers I'm unable to reproduce this bug with an up-to-date Gaufrette and vsftpd.
Could you provide more details please? For instance, what OS do you use on your FTP server, and on the server/computer running Gaufrette? Also, what FTP server do you use? Which version?...