php中的ssh2_exec无法正常工作

时间:2014-12-02 09:54:09

标签: php linux ssh centos

我正在尝试将php中的exec命令发送到远程服务器(aerohive)。但exec命令什么都不做..

我安装了ssh2扩展程序,并且验证工作正常。

以下是代码:

        if (!function_exists("ssh2_connect"))
        die("function ssh2_connect doesn't exist");

    if (!($con = ssh2_connect("myipadresherenotshowingtoyouguys", 22))) {
        echo "fail: unable to establish connection\n";
    } else {
        // try to authenticate with username root, password secretpassword
        if (!ssh2_auth_password($con, "blablabla", "blablabla!")) {
            echo "fail: unable to authenticate\n";
        } else {
            // allright, we're in!
            echo "okay: logged in...\n";

            // execute a command
            $command = 'ssid "Wentzo test2" hide-ssid';
            if (!($stream = ssh2_exec($con, $command))) {
                echo "fail: unable to execute command\n";
            } else {

                $stream2 = ssh2_exec($con, $command_save);
                // collect returning data from command
                stream_set_blocking($stream, true);
                $data = "";
                while ($buf = fread($stream, 4096)) {
                    $data .= $buf;
                }

                fclose($stream);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

检查文件php.ini是否禁用了函数disable_functions