idct-sftp-client
Library that provides wrapper methods around SSH2, SCP and SFTP to simplify file
download/upload over SSH/SCP/SFTP., (*1)
warning
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., (*2)
installation
Depending on your project include the files directly or use autoloader., (*3)
Direct usage
Just include all the required files:, (*4)
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";
Composer
Just execute:, (*5)
composer require idct/sftp-client
which will create vendor
folder with idct/sftp-client
. Then just include the
autoloader:, (*6)
include "vendor/autoload.php";
usage
After you have installed the project import required classes in your project:, (*7)
use IDCT\Networking\Ssh\SftpClient;
use IDCT\Networking\Ssh\Credentials;
Initialize instance of the class:, (*8)
$client = new SftpClient();
Create authorization mode to your SFTP server:, (*9)
When you have username and password:
$credentials = Credentials::withPassword($username, $password);
$client->setCredentials($credentials);
When you have public key:
$credentials = Credentials::withPublicKey($username, $publicKey, $privateKey, $passphrase = null);
$client->setCredentials($credentials);
$publicKey
and $privateKey
are paths to respective files., (*10)
Connect to the server
$client->connect($host);
Downloading using SFTP:
$client->download(ENTER_REMOTE_FILE_NAME);
$client->download(ENTER_REMOTE_FILE_NAME, ENTER_LOCAL_FILE_NAME);
Uploading using SFTP:
$client->upload(ENTER_LOCAL_FILE_NAME);
$client->upload(ENTER_LOCAL_FILE_NAME, ENTER_REMOTE_FILE_NAME);
Downloading using SCP:
$client->scpDownload(ENTER_REMOTE_FILE_NAME);
Uploading using SCP:
$client->scpUpload(ENTER_LOCAL_FILE_NAME,ENTER_REMOTE_FILE_NAME);
Closing connection:
$client->close();
Remote prefix, local prefix
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, (*11)
contribution
If you find any issues or want to add new features please use the Issues or Pull
Request functions: code addition is much appreciated!, (*12)
Before sending code be sure to run fix_code.sh to clean it up., (*13)
Thanks!, (*14)