phpseclib: SSH2 Examples and Notes

Action:

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');


?>

stderr and exit status

By default $ssh->exec() returns both stdout and stderr. To suppress stderr you can call $ssh->enableQuietMode(). To re-enable it call $ssh->disableQuietMode().

To get stderr separately from stdout you'll need to call $ssh->enableQuietMode() and then call $ssh->getStdError(). These functions work with $ssh->read() as well.

To get the exit status you can call $ssh->getExitStatus()