PHP code example of sandeshjangam / tiny-ssh-php

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

    

sandeshjangam / tiny-ssh-php example snippets


$ssh = (new Ssh)
    ->host($ip)
    ->port(22)
    ->user($user)
    ->password($password)
    // ->privateKey($privateKey)
    // ->privateKeyPath($privateKeyPath)
    ->connect();

$response = $ssh->execute('whoami');

$response->getOutput();  // 'username'
$response->getError();   // ''


$response->getOutput(); // It returns the `stdout`

$response->getError(); // It returns the `stderr`

$response->getExitStatus(); // 0 for success. To check if the command ran successfully

$response = $ssh->execute(['whoami', 'ls -la']);

$response = $ssh->execute('whoami && ls -la');

->timeout(60) // 60 seconds

->privateKey('private_key_content')

->privateKeyPath('/home/user/.ssh/id_rsa')

$sftp = (new Sftp)
    ->host($ip)
    ->port(22)
    ->user($user)
    ->password($password)
    // ->privateKey($privateKey)
    // ->privateKeyPath($privateKeyPath)
    ->connect();

$sftp->upload('local/file/path', 'remote/file/path')

$sftp->download('remote/file/path', 'local/file/path')

$ssh->disconnect();

$sftp->disconnect();
bash
composer