KnpLabs / Gaufrette

PHP library that provides a filesystem abstraction layer − will be a feast for your files!
http://knplabs.github.io/Gaufrette
MIT License
2.47k stars 355 forks source link

[ftp] problem with folders with spaces #285

Open shlykov opened 10 years ago

shlykov commented 10 years ago

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

stof commented 10 years ago

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

shlykov commented 10 years ago

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

staabm commented 10 years ago

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 commented 10 years ago

could you try sorrounding the path with single quotes?

staabm commented 10 years ago

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

shlykov commented 10 years ago

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.

Nek- commented 10 years ago

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

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

stof commented 10 years ago

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

andrejsstepanovs commented 8 years ago
// 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

bhattbhaskar commented 7 years ago

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 .');
akerouanton commented 7 years ago

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