Php ssh2\u连接导致错误324(网络::错误\u空\u响应):
尝试使用php列出远程sftp位置中存在的文件时,出现以下错误: 错误324网络::错误\u空\u响应: 服务器在未发送任何数据的情况下关闭了连接。在我的另一台lamp服务器上,同样的代码可以正常工作。如果你能帮忙的话,请指出我遗漏了什么。提前谢谢Php ssh2\u连接导致错误324(网络::错误\u空\u响应):,php,linux,ssh,lampp,Php,Linux,Ssh,Lampp,尝试使用php列出远程sftp位置中存在的文件时,出现以下错误: 错误324网络::错误\u空\u响应: 服务器在未发送任何数据的情况下关闭了连接。在我的另一台lamp服务器上,同样的代码可以正常工作。如果你能帮忙的话,请指出我遗漏了什么。提前谢谢 function listBuildFiles() { global $sftp_host, $sftp_username, $sftp_password, $sftp_path; $connection = ssh2_connect($sftp_
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为了确保服务器端没有问题,您可以打开控制台,在详细模式下尝试原始ssh连接:
ssh -v youruser@yourhost.com
这将跟踪服务器和客户端之间的所有交互,可能会从服务器端为您提供一些线索。使用,您可以查看正在发生的事情的完整日志。例如:
<?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的开发人员在提供支持方面也非常积极主动,因此如果您无法从日志或错误消息中找到支持,她可能会找到。您是否查看了php/apache日志?您是否查看了sshd日志?