idct / sftp-client
Library that provides wrapper methods around SSH2 and SFTP to simplify file download/upload over SSH/SCP/SFTP.
Installs: 174 934
Dependents: 0
Suggesters: 0
Security: 0
Stars: 25
Watchers: 6
Forks: 9
Open Issues: 2
Requires
- php: >=5.4.0
- ext-ssh2: >=0.12
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.11
This package is auto-updated.
Last update: 2024-11-09 01:58:22 UTC
README
Library that provides wrapper methods around SSH2, SCP and SFTP to simplify file download/upload over SSH/SCP/SFTP.
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.
installation
Depending on your project include the files directly or use autoloader.
Direct usage
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";
Composer
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";
usage
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:
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.
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
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!
Before sending code be sure to run fix_code.sh to clean it up.
Thanks!