Library that provides wrapper methods around SSH2, SCP and SFTP to simplify file download/upload over SSH/SCP/SFTP.
I am still thinking about unification of download / upload methods by passing a parameter which would define the connection type therefore method names may change.
Depending on your project include the files directly or use autoloader.
Just include all the required files:
include "/path/to/idct/sftp-client/src/AuthMode.php";
include "/path/to/idct/sftp-client/src/Credentials.php";
include "/path/to/idct/sftp-client/src/SftpClient.php";
Just execute:
composer require idct/sftp-client
which will create vendor
folder with idct/sftp-client
. Then just include the
autoloader:
include "vendor/autoload.php";
After you have installed the project import required classes in your project:
use IDCT\Networking\Ssh\SftpClient;
use IDCT\Networking\Ssh\Credentials;
Initialize instance of the class:
$client = new SftpClient();
Create authorization mode to your SFTP server:
$credentials = Credentials::withPassword($username, $password);
$client->setCredentials($credentials);
$credentials = Credentials::withPublicKey($username, $publicKey, $privateKey, $passphrase = null);
$client->setCredentials($credentials);
$publicKey
and $privateKey
are paths to respective files.
$client->connect($host);
$client->download(ENTER_REMOTE_FILE_NAME);
$client->download(ENTER_REMOTE_FILE_NAME, ENTER_LOCAL_FILE_NAME);
$client->upload(ENTER_LOCAL_FILE_NAME);
$client->upload(ENTER_LOCAL_FILE_NAME, ENTER_REMOTE_FILE_NAME);
$client->scpDownload(ENTER_REMOTE_FILE_NAME);
$client->scpUpload(ENTER_LOCAL_FILE_NAME,ENTER_REMOTE_FILE_NAME);
$client->close();
Prefixes set using methods: setRemotePrefix
and setLocalPrefix
allow to set
common directories for storage. Please follow phpDoc of respective upload/download
methods to know when
If you find any issues or want to add new features please use the Issues or Pull Request functions: code addition is much appreciated!
Before sending code be sure to run fix_code.sh to clean it up.
Thanks!