PHP - ssh2读取输出流

时间:2012-06-15 21:04:04

标签: php ssh

我无法在PHP中显示SSH流的输出。这是我的代码:

$output = ssh2_exec($sshCon, $sshCommand);

stream_set_blocking($output, true);

echo stream_get_contents($output);

输出为空白。该命令肯定在运行。我也试过这里给出的解决方案: Empty PHP SSH2 stream contents, even with stream_set_blocking?

输出应该是进程ID,只是为了让您知道。

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试phpseclib, a pure PHP SSH implementation

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec($sshCommand);
?>