phizzl / php-ssh2-client
Library for transfering files via SSH2
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/phizzl/php-ssh2-client
Requires
- ext-ssh2: *
- monolog/monolog: ^1.23
This package is auto-updated.
Last update: 2023-03-12 23:45:13 UTC
README
A SSH2 client written in PHP
Authentication
You may choose between the authentication modes pubkey, password and none.
Authentication with password
$auth = new PasswordAuthentication("vagrant", "vagrant");
Authentication with public and private keypair
$auth = new PublicKeyAuthentication("vagrant", "/path/to/id_rsa.pub", "/path/to/id_rsa", "keypassword");
No authentication
$auth = new NoneAuthentication("vagrant");
Creating the SSH2 session
After you configured your authentication you may create the SSH2 session and pass the authentication to it.
$auth = new PasswordAuthentication("vagrant", "vagrant"); $session = new SshSession("localhost", 22, $auth);
Creating the SSH2 client
Now that you have a session you can create the SSH2 client and pass the session to it.
$auth = new PasswordAuthentication("vagrant", "vagrant"); $session = new SshSession("localhost", 22, $auth); $sshClient = new SshClient($session);
Using the SSH2 client
After you created the SSH2 client you are ready to use it.
$sshClient->sendFile('/local/path/to/file.txt, '~/uploads/file.txt');
$sshClient->receiveFile('~/downloads/remote.file', '/local/path/local.file');
$sshClient->removeFile('~/downloads/remote.file');
$sshClient->createDirectory('~/uploads/newdir');
$sshClient->removeDirectory('~/uploads/newdir', true)
$sshClient->sendDirectory('/local/dir', '~/uploads/newdir');
$sshClient->removeDirectory('~/uploads/newdir', true);
$sshClient->receiveDirectory('~/downloads/backup', '/local/dir/backup');