phizzl/php-ssh2-client

This package is abandoned and no longer maintained. No replacement package was suggested.

Library for transfering files via SSH2

v1.0.0 2017-09-28 21:37 UTC

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');