Gaufrette icon indicating copy to clipboard operation
Gaufrette copied to clipboard

[ftp] problem with folders with spaces

Open shlykov opened this issue 10 years ago • 11 comments

ftp_rawlist() function returns empty result if there is a folder with space. You can use ftp_nlist() which does not have this problem.

shlykov avatar May 05 '14 09:05 shlykov

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

stof avatar May 05 '14 11:05 stof

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

shlykov avatar May 05 '14 12:05 shlykov

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)

staabm avatar May 05 '14 12:05 staabm

could you try sorrounding the path with single quotes?

staabm avatar May 05 '14 12:05 staabm

per https://bugs.php.net/bug.php?id=15231 it could also help to escape the space with \

staabm avatar May 05 '14 12:05 staabm

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.

shlykov avatar May 05 '14 12:05 shlykov

This lib looks great and probably fix the problem. We should maybe implement it. cc @l3l0

https://github.com/ngyuki/php-ftp-client

Nek- avatar May 15 '14 15:05 Nek-

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

stof avatar May 15 '14 15:05 stof

// 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

andrejsstepanovs avatar Jun 13 '16 15:06 andrejsstepanovs

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 .');

bhattbhaskar avatar Jun 27 '17 18:06 bhattbhaskar

@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?...

akerouanton avatar Jun 27 '17 22:06 akerouanton