Пример #1
0
 /**
  * Construct new SSH2 Session.
  *
  * @param ConnectorContract     $connection
  * @param AuthenticatorContract $authentication
  *
  * @throws ConnectionException     if connection could not be established.
  * @throws AuthenticationException if the user could not be authenticated.
  */
 public function __construct(ConnectorContract $connection, AuthenticatorContract $authentication)
 {
     $session = $connection->createSessionResource();
     if (!$session) {
         throw new ConnectionException('Could not establish SSH connection');
     }
     if (!$authentication->authenticateSessionResource($session)) {
         throw new AuthenticationException('Could not authenticate user');
     }
     $this->session = $session;
     $this->terminal = Terminal::create();
 }
Пример #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__));