PHP code example of chris-doehring / ssh
1. Go to this page and download the library: Download chris-doehring/ssh 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/ */
chris-doehring / ssh example snippets
Ssh::create('user', 'host')->execute('your favorite command');
$process = Ssh::create('user', 'example.com')->execute('your favorite command');
$process->isSuccessful();
$process->getOutput();
$process = Ssh::create('user', 'example.com')->execute([
'first command',
'second command',
]);
$port = 123;
Ssh::create('user', 'host', $port);
Ssh::create('user', 'host')->usePort($port);
Ssh::create('user', 'host')->usePrivateKey('/home/user/.ssh/id_rsa');
Ssh::create('user', 'host')->disableStrictHostKeyChecking();
Ssh::create('user', 'host')->upload('path/to/local/file', 'path/to/host/file');
Ssh::create('user', 'host')->download('path/to/host/file', 'path/to/local/file');
Ssh::create('user', 'host')->configureProcess(fn (Process $process) => $process->setTimeout(null));
Ssh::create('user', 'host')->onOutput(fn($type, $line) => echo $line)->execute('whoami');