개요[ | ]
- PHP class my_ssh2
- 대충 만들어 본 PHP ssh2 wrapper
PHP
Copy
class my_ssh2 {
private $conn;
function __construct( $address, $username, $password, $port=22 ) {
$this->conn = ssh2_connect( $address );
if( !ssh2_auth_password($this->conn, $username, $password) ) {
die('Authentication Failed...');
}
}
function exec( $command ) {
$stream = ssh2_exec($this->conn, $command);
stream_set_blocking($stream, true);
return stream_get_contents($stream);
}
function passthru( $str ) {
$stream = ssh2_exec($this->conn, $str);
stream_set_blocking($stream, true);
while( $line = fgets($stream) ) { flush(); echo $line; }
}
function disconnect() {
$this->exec( 'exit' );
$this->conn = null;
}
function __destruct() {
$this->disconnect();
}
}