SFTP in PHP without the pain
(php, open-source) 1 min read by Bartosz Pachołek
idct/sftp-client is being rebuilt for PHP 8.2: typed errors, atomic uploads, resume, retries and host-key checks.
idct/sftp-client started in 2014 as a set of wrapper methods around PHP's SSH2 extension. It is being rebuilt as a typed PHP 8.2+ library for predictable error handling, host-key verification and a clean seam for unit tests.
What the 1.0 work adds
- Atomic uploads and resume: a transfer either lands completely or not at all, and an interrupted one can continue.
- Streaming sources and sinks, so a file can go from S3 to SFTP without a temporary copy.
- Progress callbacks for long transfers.
- Retry policies for flaky links.
- Recursive directory operations.
- Known-hosts and fingerprint verification, and opt-in checksum verification.
Requirements
PHP 8.2 or newer, ext-ssh2 1.4+ and libssh2 1.10+. On Debian or Ubuntu that is apt-get install php-ssh2; on Alpine, apk add php-pecl-ssh2.
composer require idct/sftp-client
The library is MIT licensed and lives on GitHub, with runnable examples and an upgrade guide from 0.x.