league/flysystem-sftp-v3
Flysystem SFTP adapter using phpseclib v3. This is a sub-split of the Flysystem project; install via composer to add SFTP storage support to your Flysystem setup. For issues and PRs, use the main Flysystem repository and docs.
Install the package:
composer require league/flysystem-sftp-v3 phpseclib/phpseclib:^3.0
(Note: phpseclib/phpseclib is a required dependency but must be explicitly required due to sub-split isolation.)
Basic usage in Laravel:
config/filesystems.php:
'sftp' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
'port' => env('SFTP_PORT', 22),
'username' => env('SFTP_USERNAME'),
'password' => env('SFTP_PASSWORD'), // or use 'privateKey' + 'passphrase'
'privateKey' => storage_path('app/id_rsa'),
'timeout' => 10,
'root' => '/remote/path',
],
Storage facade:
Storage::disk('sftp')->put('remote-file.txt', 'content');
First use case: Upload user-generated reports to a secure server for archival or sharing.
.env for flexibility and security.Storage::cloud() alias if SFTP is your primary cloud storage.privateKey) over passwords for production.phpseclib’s Key::load() for encrypted private keys with passphrase.copy(), move(), and listContents() for batch operations:
$files = Storage::disk('sftp')->listContents('reports/');
foreach ($files as $file) {
Storage::disk('local')->put($file['path'], Storage::disk('sftp')->read($file['path']));
}
League\Flysystem\FilesystemException and inspect reason() for context (e.g., auth failure, path not found).phpseclib/phpseclib package must be installed explicitly—the sub-split doesn’t auto-include it. Miss this, and you’ll get Class 'phpseclib3\Net\SFTP not found` errors.DIRECTORY_SEPARATOR-agnostic paths (e.g., 'reports/' . date('Y') . '/report.pdf').readfile() fallback if streaming large files; use readStream() instead:
$stream = Storage::disk('sftp')->readStream('large-file.dat');
readfile($stream['stream']);
LoggerInterface (though the v3 adapter doesn’t expose logger config directly—extend or decorate if needed).sftp->exec('pwd') workaround for path resolution.SftpAdapter to inject custom authentication flow (e.g., dynamic credential rotation from AWS Secrets Manager).How can I help you explore Laravel packages today?