laravelsftpflysystem

Cannot list files in directory with phpleague flysystem sftp v3


We have recently switched from v1 to v3 of the flysystem sftp package. However, the v3 version is throwing the following error when trying to access files in an existing directory like so:

$disk = Storage::disk('sftp');
$directories = $disk->directories('documents'); // this will only be used for testing to dump and check if the directory exists
$files = $disk->files('documents/whitepapers');

dump($directories) will succesfully return:

array:1 [
  0 => "documents/whitepapers"
]

However $files cannot be used, since an error is being thrown:

League\Flysystem\UnableToListContents
Unable to list contents for 'documents/whitepapers', shallow listing

Reason: Undefined array key "type"

So the Undefined array key "type" of the StorageAttributes is causing the issue. However, I have no idea how to fix this. It worked fine in v1 of the package with the same server, directories and files.

Is that an issue in the package or am I doing something wrong here?

The code is running on PHP 8.1.8 and Laravel 9.30.1 with league/flysystem-sftp-v3 3.5.2


Solution

  • Ran into a similar issue today and found it was solved in a new release.

    Pull Request: https://github.com/thephpleague/flysystem/issues/1563

    Commit: https://github.com/thephpleague/flysystem/commit/57d6217b5c5783eb7ae12270ca364f805eb0e919

    Just upgrade league/flysystem-sftp-v3 to version 3.6 or later.

    composer require league/flysystem-sftp-v3:^3.6.0