【发布时间】:2012-05-17 18:14:08
【问题描述】:
我正在尝试使用ssh2_exec 函数从带有 PHP 的 ssh2 库的远程服务器运行 SSH 命令。
我没有从 SSH 将我想要的东西返回给我,而是得到了这个:
resource(2) of type (stream)
如果重要的话,有时2 是3。
这是我尝试使用的代码:
<?php
$connection = ssh2_connect('ssh.example.com', 22);
ssh2_auth_password($connection, 'root', 'password');
if($output = ssh2_exec($connection, 'uptime')) {
var_dump($output);
}
工作解决方案:
<?php
$connection = ssh2_connect('ssh.example.com', 22);
ssh2_auth_password($connection, 'root', 'password');
if($output = ssh2_exec($connection, 'uptime')) {
stream_set_blocking($output, true);
echo stream_get_contents($output);
}
【问题讨论】: