phpseclib 即使在简单的命令上也不会返回任何结果


phpseclib return no result even on simple command

我想通过php添加ssh用户。所以我尝试phpseclib。不幸的是,该脚本不返回任何结果,也不返回任何用户创建的结果。然后我尝试ls -la制作一个简单的命令。仍然没有结果,只是加载几秒钟并返回空白页。

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');  
include('Net/SSH2.php');
$ssh = new Net_SSH2('xxx.xxx.xxx.xxx'); 
if (!$ssh->login('root', 'abc123')) { 
 exit('Login Failed'); 
 echo $ssh->exec('ls -la');
}

我使用 PHP 5.3.3 和 Centos 6.5

P/S: 我检查了 apache log 和/var/log/messages。没有错误。

exit() 命令将在它之后终止后续代码。您可能希望:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');  
include('Net/SSH2.php');
$ssh = new Net_SSH2('xxx.xxx.xxx.xxx'); 
if (!$ssh->login('root', 'abc123')) { 
 exit('Login Failed'); 
}
echo $ssh->exec('ls -la');