我一直在尝试按照以下网址找到示例代码:
http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/
我能够连接到我的交换机,并成功进行身份验证。当我尝试运行命令时BUt,它失败并显示此帖子标题中的错误消息。
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("10.14.123.12", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "root", "mypassword")) {
echo "fail: unable to authenticate\n";
} else {
// execute a command
if (!($stream = ssh2_exec($con, "show mac-address" ))) {
echo "fail: unable to execute command\n";
} else {
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
}
}
}
我正在尝试执行show mac-address命令。 我已经确认这是switch命令的正确语法 - 手动尝试...并且它返回数据就好了。 有什么建议? 感谢。