我想创建到teamspeak服务器的ssh连接。通过这个原始连接,应该可以从控制台输入和获取命令。
什么是爱
$socket = @ssh2_connect($this->runtime['host'], $this->runtime['queryport']);
if($socket === false)
{
$this->addDebugLog('Error: connection failed!');
return $this->generateOutput(false, array('Error: connection failed!'), false);
}
else
{
if(@ssh2_auth_password($socket, $this->escapeText($username), $this->escapeText($password)))
{
if(($shell = @ssh2_shell($socket, "raw")) === false)
{
return $this->generateOutput(false, array('Error: failed to open a secure shell on server!'), false);
}
else
{
$this->runtime['ssh'] = $socket;
$this->runtime['socket'] = $shell;
@stream_set_timeout($this->runtime['socket'], $this->runtime['timeout']);
@stream_set_blocking($this->runtime['socket'], true);
return $this->generateOutput(true, array(), true);
}
}
else
{
return $this->generateOutput(false, array('Error: invalid loginname or password!'), false);
}
}
原因
@stream_set_blocking($this->runtime['socket'], true);
这一行我的脚本正在超时运行。我也有一些问题,fgets总是返回一个空结果。我做错什么了吗?