我正在尝试使用ssh2
函数从具有PHP的ssh2_exec
库的远程服务器上运行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);
}
最佳答案
Return Values
Returns a stream on success or FALSE on failure.
stream是类似文件的对象。您可以使用stream functions或fread之类的文件句柄函数从中获取数据。
例如。
$string = stream_get_contents($stream);
$line = stream_get_line($stream);
$fivebytes = fread($stream, 5);
关于php - SSH2返回 “resource(2) of type (stream)”(PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10641242/