Example #1
0
*/
$terminal = Terminal::create()->width(80, 'chars')->height(25, 'chars');
/*
| Execute a single command on the remote server
| ----------------------------------------------
| Capture its output and echo it on the local screen.
*/
echo 'Output of »echo $HOME $PWD«: ';
echo $ssh->withTerminal($terminal)->execute('echo $HOME $PWD');
echo PHP_EOL;
/*
| Send a file via SCP
| --------------------
| Simply send this file (demo.php) to the remote server.
*/
if ($ssh->sendFile(__FILE__, basename(__FILE__))) {
    printf('File: %s was sent to the remote server' . PHP_EOL, basename(__FILE__));
}
/*
| Open a shell on the remote server
|--------------------------
| Open a shell.
| Execute a few commands.
| Logout.
| Print the output from the shell.
| The shell is automatically closed when callback returns.
*/
echo $ssh->withTerminal($terminal)->shell(function ($shell) {
    $captured_output = $shell->writeline('echo The home dir is: $HOME')->writeline('echo the contents of $PWD is:; ls -lah')->writeline('logout')->wait(0.3)->readToEnd();
    return $captured_output;
});