ssh2_connect导致错误324(net :: ERR_EMPTY_RESPONSE):

当试图列出使用PHP远程sftp位置存在的文件,我得到这个错误:

错误324(net :: ERR_EMPTY_RESPONSE):

服务器closures连接而不发送任何数据。 在我的另一台灯服务器上,相同的代码工作正常。 请指出我错过了什么,如果你能帮助请。 提前致谢。

function listBuildFiles() { global $sftp_host, $sftp_username, $sftp_password, $sftp_path; $connection = ssh2_connect($sftp_host); // Authenticate if (!ssh2_auth_password($connection, $sftp_username, $sftp_password)) { throw new Exception('Unable to connect.'); } // Create our SFTP resource if (!$sftp = ssh2_sftp($connection)) { throw new Exception('Unable to create SFTP connection.'); } /** * Now that we have our SFTP resource, we can open a directory resource * to get us a list of files. Here we will use the $sftp resource in * our address string as I previously mentioned since our ssh2:// * protocol allows it. */ $files = array(); $dirHandle = opendir("ssh2.sftp://$sftp$sftp_path"); $i=0; // Properly scan through the directory for files, ignoring directory indexes (. & ..) while (false !== ($file = readdir($dirHandle))) { if ($file != '.' && $file != '..') { $files[$i] = $file; $i++; } } echo '<select name="buildName">'; echo '<option>Please Select a build</option>'; foreach ($files as $filename) { echo "<option value=\"$filename\">$filename</option>"; } echo '</select>'; ssh2_exec($connection, "exit"); 

谢谢,Ujjwal

使用phpseclib(一个纯粹的PHP SFTP实现) ,您可以看到发生了什么的完整日志。 例:

 <?php include('Net/SFTP.php'); define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); $sftp = new Net_SFTP('www.domain.tld'); if (!$sftp->login('username', 'password')) { exit('Login Failed'); } // puts a three-byte file named filename.remote on the SFTP server $sftp->put('filename.remote', 'xxx'); echo $ssh->getLog(); print_r($ssh->getErrors()); ?> 

phpseclib的开发人员也非常主动的提供支持,所以如果你不能从日志或者错误信息中找出他可能的。

只是为了确保服务器端没有问题,你可以打开一个控制台,并在详细模式下尝试一个原始的SSH连接:

 ssh -v youruser@yourhost.com 

这跟踪服务器和客户端之间的所有交互,也许给你一些线索从服务器端。