PHP code example of william-costa / php-ssh
1. Go to this page and download the library: Download william-costa/php-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/ */
william-costa / php-ssh example snippets
PENDÊNCIAS
use WilliamCosta\SecureShell\SSH;
//INSTÂNCIA
$obSSH = new SSH;
//CONEXÃO
if(!$obSSH->connect('172.17.0.1',2222)){
die('Conexão falhou');
}
//AUTENTICAÇÃO VIA USUÁRIO E SENHA
if(!$obSSH->authPassword('wdev','123456')){
die('Autenticação falhou');
}
//AUTENTICAÇÃO VIA PAR DE CHAVES
if(!$obSSH->authPublicKeyFile('wdev','chave_rsa.pub','chave_rsa.pem')){
die('Autenticação falhou');
}
//EXECUTA COMANDOS
$stdIo = $obSSH->exec('ls -l',$stdErr);
echo "STDERR:\n".$stdErr;
echo "STDIO:\n".$stdIo;
//DESCONECTA
$obSSH->disconnect();
shell
composer