Esempio n. 1
0
 /**
  * Start a shell with the currenet terminal settings.
  *
  * sicnature of callback:
  * mixed callback(ExecutionStream $io)
  *
  * @param callable $callback
  *
  * @return mixed the result from executing callback.
  */
 public function shell(callable $callback)
 {
     $stream = new ExecutionStream(ssh2_shell($this->session, 'vanilla', null, $this->terminal->getWidth(), $this->terminal->getHeight(), $this->terminal->getDimensionUnits()));
     $result = $callback($stream->async());
     $stream->close();
     return $result;
 }
Esempio n. 2
0
$sftp->putContents('testFile.txt', $random);
if ($random == $sftp->getContents('testFile.txt')) {
    echo 'File testFile.txt was written on remote server, and the contents verified';
    echo PHP_EOL;
} else {
    echo 'File testFile.txt was written on remote server, but the contents could not be verified';
    echo PHP_EOL;
}
/*
| Create terminal settings
|--------------------------
| This step is optional.
| You do not need to call $ssh-withTerminal()
| If you don't. Default terminal settings will be used.
*/
$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__));