【问题标题】:ssh2_exec in php not workingphp中的ssh2_exec不起作用
【发布时间】:2015-01-30 12:33:06
【问题描述】:

我正在尝试将 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);
            }
        }
    }

【问题讨论】:

  • 你能打开错误报告并向我们显示错误信息吗?
  • 没有给出错误! :(

标签: php linux ssh centos


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2019-02-15
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多