php ssh2连接到HP交换机 - 失败并显示“警告:ssh2_exec()[function.ssh2-exec]:无法请求在远程主机上执行命令”

时间:2012-08-06 17:03:43

标签: php ubuntu apache2

我一直在尝试按照以下网址找到示例代码:

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命令的正确语法 - 手动尝试...并且它返回数据就好了。 有什么建议? 感谢。

0 个答案:

没有答案