PHP code example of phizzl / php-ssh2-client

1. Go to this page and download the library: Download phizzl/php-ssh2-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phizzl / php-ssh2-client example snippets


$auth = new PasswordAuthentication("vagrant", "vagrant");

$auth = new PublicKeyAuthentication("vagrant", "/path/to/id_rsa.pub", "/path/to/id_rsa", "keypassword");

$auth = new NoneAuthentication("vagrant");

$auth = new PasswordAuthentication("vagrant", "vagrant");
$session = new SshSession("localhost", 22, $auth);

$auth = new PasswordAuthentication("vagrant", "vagrant");
$session = new SshSession("localhost", 22, $auth);
$sshClient = new SshClient($session);

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