<?php
if (!function_exists(“ssh2_connect”)) die(“function ssh2_connect doesn’t exist”);
if (!($con = ssh2_connect(‘192.168.155.123’, 22))) {
echo “fail: unable to establish connection\n”;
} else {
// try to authenticate with username root, password secretpassword
if (!ssh2_auth_password($con, ‘root’, ‘juniper@123’)) {
echo “fail: unable to authenticate\n”;
} else {
// allright, we’re in!
echo “okay: logged in…\n”;
//////////////////////////////////////////////////////////////////////////
$stream = ssh2_exec($con, ‘whoami’);
// force PHP to wait for the output
stream_set_blocking($stream, true);
// read the output into a variable
$data = ”;
while($buffer = fread($stream, 4096)) {
$data .= $buffer;
}
// close the stream
fclose($stream);
// print the response
echo $data;
//////////////////////////////////////////////////////////////////////////
} //end else can authenticate
} // end else can connect
?>
===============================
*** used php_ssh2.dll ***
config php.ini
================================
extension=php_openssl.dll
extension=php_ssh2.dll
Leave a Reply