thephpleague / flysystem

Abstraction for local and remote filesystems
https://flysystem.thephpleague.com
MIT License
13.36k stars 827 forks source link

ftp_rawlist returns empty list on some ftp servers if path ends with slash #1641

Open jacekkarczmarczyk opened 1 year ago

jacekkarczmarczyk commented 1 year ago

Bug Report

Q A
Flysystem Version 3.2.12
Adapter Name FTP
Adapter version 3.10.3

Summary

ftpRawlist method forces the path to end with slash, however on some ftp servers it breaks things. If I manually set set $path variable to "/foo" I'm getting the correct list of files, if I set it to "/foo/" - I get empty list.

The FTP server that is causing the problem is called Qnap. My suggestion would be to not add the ending slash (or actually forcing it to be removed, unless it's just / path), however I'm not sure if that won't break other servers, so maybe better solution would be to add an option to FtpConnectionOptions to specify whether slash should be added or removed in ftpRawlist method.

From what I've checked removing the slash didn't break other functionalities like getting the contents of the file etc

How to reproduce

    private function ftpRawlist(string $options, string $path): array
    {
        $path = rtrim($path, '/') . '/';
        // uncomment one of the lines below
        // $path = '/foo'; 
        // $oath = '/foo/';
        $connection = $this->connection();
print_r $filesystem->listContents('whatever')->toArray()
marclangesauels commented 9 months ago

We experience the same issue with our Qnap FTP Server. Removing the trailing slash, as mentioned fixes the listing.