Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

diaglyph's avatar

Using league's SFTP adapter with Flysystem

I've installed league's SFTP adapter for Flysystem.

I need to SFTP to a server to grab a file. Doing a test I can connect successfully, but when I call listContents() it returns null. For testing, I let it default to the user's home directory and it does contain files, so I should be getting files listed. Why would it return null?

Here is my test code. I've created a dummy function that I can run in tinker: (hiding IP, user and password for obvious reasons)


// Use
use League\Flysystem\Filesystem;
use League\Flysystem\Sftp\SftpAdapter;

// Function body
        $adapter = new SftpAdapter([
                                       'host'     => 'x.x.x.x',
                                       'port'     => 22,
                                       'username' => 'xxx',
                                       'password' => 'xxx',
                                       'timeout'  => 10,
                                   ]);

        $filesystem = new Filesystem($adapter);
        $adapter->connect();
        if ($adapter->isConnected()) {
            echo "connected\r\n";
        }
        $ls = $filesystem->listContents('Desktop');

The user folder has a folder called Desktop, which has a couple of files. So when listContents() is called, it should be showing these files. It returns null instead.

0 likes
2 replies
diaglyph's avatar
diaglyph
OP
Best Answer
Level 3

I guess there seems to be an issue with this "plugin", so I've removed it and tried "idct/sftp-client" instead, which works without any problems and fairly easy to use.

ElwinB's avatar

Could you try:

$ls = $filesystem->listContents('Desktop', true);

In order to set the passive mode. This helped me out in the past.

Please or to participate in this conversation.