flysystem icon indicating copy to clipboard operation
flysystem copied to clipboard

Directory listing fails with hardcoded options

Open Arkitecht opened this issue 3 years ago • 3 comments

Bug Report

Q A
BC Break no
Version 1.1.9

Summary

After successfully connecting to an FTP server, I am unable to get the listing of files in the directory. When I manually go into the code and clear the options variable in method ftpRawlist the listing comes back successfully.

These options are hardcoded in listDirectoryContents on line 505 : $options = $recursive ? '-alnR' : '-aln';

I am using flysystem through Laravel (8.70.2) storage.

How to reproduce

I am not sure if this is unique to this particular server, or what is causing the issue. When I connect to the FTP server (220-FileZilla Server 1.1.0) manually and try those command they error as well:

ftp> ls -a
227 Entering Passive Mode (209,249,197,15,73,115)
450 Couldn't open the file
ftp> ls -aln
227 Entering Passive Mode (209,249,197,15,76,133)
450 Couldn't open the file
ftp> ls -ln
227 Entering Passive Mode (209,249,197,15,77,221)
450 Couldn't open the file

If I do an ls with no arguments, the listing comes back successfully.

This update fixes it for me, I can submit as a PR if this makes sense:

    /**
     * @return bool
     */
    protected function isFileZillaServer()
    {
        $response = ftp_raw($this->connection, 'SYST');

        return stripos(implode(' ', $response), 'FileZilla') !== false;
    }

    /**
     * The ftp_rawlist function with optional escaping.
     *
     * @param string $options
     * @param string $path
     *
     * @return array
     */
    protected function ftpRawlist($options, $path)
    {
        $connection = $this->getConnection();

        if ($this->isPureFtpd) {
            $path = str_replace([' ', '[', ']'], ['\ ', '\\[', '\\]'], $path);
        }

        if ( $this->isFileZillaServer()) {
            $options = '';
        }

        return ftp_rawlist($connection, $options . ' ' . $this->escapePath($path));
    }

Arkitecht avatar Jan 06 '22 15:01 Arkitecht

I think this issue and issue https://github.com/thephpleague/flysystem/issues/1387 describe the same issue. I hope a PR for this can be merged in some way, we also ran into and disabled asserts for the time being to work around it.

johanrosenson avatar Jan 14 '22 09:01 johanrosenson

I have the very same problem with pyftpdlib server. It comes from https://github.com/thephpleague/flysystem/blob/3.x/src/Ftp/FtpAdapter.php#L543 where the options are concatenated with the path. If the server does not support the command it returns an empty array.

When removing the options it works as expected.

pyrsmk avatar Jan 31 '22 19:01 pyrsmk

We also run into this problem with FileZilla Server v1.3.0

marvinschroeder avatar Apr 01 '22 10:04 marvinschroeder