Ubuntu16.04上PHP的SSH2扩展不工作
我尝试使用PHP+SSH2扩展来重新启动我的Ubuntu 16.04机器。我已成功安装SSH2扩展: 然后我写了PHP代码,它成功地登录但没有执行命令Ubuntu16.04上PHP的SSH2扩展不工作,php,ubuntu-16.04,ssh2-exec,Php,Ubuntu 16.04,Ssh2 Exec,我尝试使用PHP+SSH2扩展来重新启动我的Ubuntu 16.04机器。我已成功安装SSH2扩展: 然后我写了PHP代码,它成功地登录但没有执行命令 <?php if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); if(!($con = ssh2_connect("localhost", 22))){ echo "fail: unable to establish conn
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect("localhost", 22))){
echo "fail: unable to establish connection\n";
} else {
if(!ssh2_auth_password($con, "lam", "root")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
if (!($stream = ssh2_exec($con, "reboot" ))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
}
}
}
?>