duankuai6991 2012-08-06 17:03
浏览 111

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

I've been trying to follow the example code found at:

http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/

I am able to connect to my switch, and successfully authenticate. BUt when I try to run a command, it fails with the error message in the title of this post.

      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
";
            } else {
                 // try to authenticate with username root, password secretpassword
                 if(!ssh2_auth_password($con, "root", "mypassword")) {
                          echo "fail: unable to authenticate
";
                  } else {
                      // execute a command
                      if (!($stream = ssh2_exec($con, "show mac-address" ))) {
                           echo "fail: unable to execute command
";
                      } else {
                             stream_set_blocking($stream, true);
                             $data = "";
                            while ($buf = fread($stream,4096)) {
                             $data .= $buf;
                      }
                      fclose($stream);
                  }
             }
         }

It's dying on the line where I'm trying to execute the show mac-address command. I've confirmed that this is the correct syntax for the switch command - tried it manually...and it returns data just fine. Any suggestions? Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料