Wrapper class for PHP's SSH2 extension. The base class was created by Jamie Munro taken from this article.
$ composer require lodev09/php-ssh2
// connect
$auth = new \SSH2\Password(SFTP_USER, SFTP_PASSWORD);
$sftp = new \SSH2\SFTP(SFTP_HOST, $auth);
if ($sftp->is_connected() && $sftp->is_authenticated()) {
// upload
$sftp->put('/path/to/my/local/file', '/remote/file');
// download
$sftp->get('/remote/file', '/local/destination/file');
}
Common helper methods includes:
SFTP::mv
- move remote fileSFTP::rm
- delete remote fileSFTP::list
- list remote filesSFTP::is_dir
- check if path is a directorySFTP::exists
- check if path exists
Other native methods can be called as well for example:
// ssh2_sftp_mkdir
$sftp->mkdir(...);
Just a pure wrapper of the native ssh2_scp_xxx
functions.
// ssh2_scp_recv
$scp->recv(...);
All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at www.lodev09.com or email me at lodev09@gmail.com
- Jamie Munro
- Jovanni Lo @lodev09
Released under the MIT License. See LICENSE file.