PHP code example of herzult / php-ssh

1. Go to this page and download the library: Download herzult/php-ssh 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/ */

    

herzult / php-ssh example snippets




// simple configuration to connect "my-host"
$configuration = new Ssh\Configuration('my-host');



// simple configuration to connect "my-host"
$configuration = new Ssh\SshConfigFileConfiguration('/Users/username/.ssh/config', 'my-host');
$authentication = $configuration->getAuthentication('optional_passphrase', 'optional_username');



// ... the configuration creation

$session = new Ssh\Session($configuration);



$configuration = new Ssh\Configuration('myhost');
$authentication = new Ssh\Authentication\Password('John', 's3cr3t');

$session = new Session($configuration, $authentication);



$configuration = new Ssh\SshConfigFileConfiguration('~/.ssh/config', 'my-host');

$session = new Session($configuration, $configuration->getAuthentication());



// the session creation

$sftp = $session->getSftp();



// ... the session creation

$publickey = $session->getPublickey();



// ... the session creation

$exec = $session->getExec();

echo $exec->run('ls -lah');