PHP code example of faraweilyas / sshbunny

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

    

faraweilyas / sshbunny example snippets




use SSHBunny\SSHBunny;

tput of command executed while ->getData(TRUE) will dispay the output
$sshBunny = (new SSHBunny('local'))
    ->initialize()
    ->exec("echo 'Hello World'")
    ->getData(TRUE);



use SSHBunny\SSHBunny;

L : define('TEST_HOST',    "138.222.15.1");
defined('PORT')         ? NULL : define('PORT',         "22");
defined('USERNAME')     ? NULL : define('USERNAME',     "ubuntu");
defined('PUBLIC_KEY')   ? NULL : define('PUBLIC_KEY',   'id_ssl.pub');
defined('PRIVATE_KEY')  ? NULL : define('PRIVATE_KEY',  'id_ssl');

$sshBunny = (new SSHBunny('remote', 'KEY', HOST, PORT, USERNAME))
    ->setKeys(PUBLIC_KEY, PRIVATE_KEY)
    ->initialize()
    ->exec("echo 'Hello World'")
    ->getData(TRUE);

$sshBunny = (new SSHBunny('remote', 'KEY', HOST, PORT, USERNAME))
    ->setKeys(PUBLIC_KEY, PRIVATE_KEY)
    ->initialize()
    // Multiple commands
    ->exec("echo 'Hello World'", "cd /var/www/html")
    // Method chaining
    ->exec("ls -la")
    ->getData(TRUE);

// Will return the result of executed command output
$sshBunny
    ->exec("ls -la")
    ->getData();
// Will display the result of executed command output
$sshBunny
    ->exec("ls -la")
    ->getData(TRUE);

// Will clear the first executed command output and return the next executed command output
$sshBunny
    ->exec("ls -la")
    ->clearData()
    ->exec("whoami")
    ->getData(TRUE);

// Will run the commands provided and display the result then disconnect from the server
$sshBunny
    ->exec("ls -la", "whoami")
    ->getData(TRUE)
    ->disconnect();