Php ftp列表/ftp列表随机导致错误500

Php ftp列表/ftp列表随机导致错误500,php,ftp,Php,Ftp,我想使用我的web服务器上的FTP_列表对我的FTP服务器进行爬网 它确实有效,但并不总是有效 我的FTP服务器使用IIS托管在windows server 2016上。 它是一个简单的FTP帐户(不是FTPS和w/o证书) 我的PHP服务器运行托管在1和1上的PHP V7.2.30。 内存限制设置为128M 代码如下(我使用AJAX查询页面(POST方法): display.php $ftp_server = "xxx.xxx.xxx.xxx"; $ftp_username = "xxxxxx

我想使用我的web服务器上的FTP_列表对我的FTP服务器进行爬网

它确实有效,但并不总是有效

我的FTP服务器使用IIS托管在windows server 2016上。 它是一个简单的FTP帐户(不是FTPS和w/o证书)

我的PHP服务器运行托管在1和1上的PHP V7.2.30。 内存限制设置为128M

代码如下(我使用AJAX查询页面(POST方法):

display.php

$ftp_server = "xxx.xxx.xxx.xxx";
$ftp_username = "xxxxxxxxxxx";
$ftp_userpass = "xxxxxxxxxxxxxx";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to the FTP server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

$scan = ftp_get_filelist($ftp_conn, '.');
var_dump($scan);
function.php

function ftp_get_filelist($ftp_conn, $path){
 $Win=false;
 $contents = ftp_rawlist ($ftp_conn, $path);
 $Output = array();
 $i = 0;

 foreach ($contents as $Current) {
  $Split = preg_split('[ ]', $Current, 9, PREG_SPLIT_NO_EMPTY);
  if ($Split[0] != 'total') {
   $Output[$i]['isdir']     = ($Split[0] {0} === 'd');
   $Output[$i]['perms']     = $Split[0];
   $Output[$i]['number']    = $Split[1];
   $Output[$i]['owner']     = $Split[2];
   $Output[$i]['group']     = $Split[3];
   $Output[$i]['size']      = $Split[4];
   $Output[$i]['month']     = $Split[5];
   $Output[$i]['day']       = $Split[6];
   $Output[$i]['time']   = $Split[7];
   $Output[$i]['full_date'] = '2020-'.$Split[5].'-'.$Split[6].' '.$Split[7];
   $Output[$i]['name']      = $Split[8];
   $i++;
  }
 }
 return !empty($Output) ? $Output : FALSE;

}
所有这些看起来都很有效(但今年,我还没有成功得到它,但这是另一个问题)

所以当我运行它时,我有文件和文件夹的列表。 我还在工作, 我再次刷新,然后类似于加载,然后PHP服务器发送错误:

错误500-内部服务器错误

发生2次5次的错误对我来说真的很难调试

我试图查看日志文件,发现请求的错误代码为500,但没有更多信息:

xxx.xxx.xxx.xxx - - [08/May/2020:06:05:50 +0200] "POST display.php HTTP/1.1" 500 669 www.xxxxxx.com "https://xxxxxx.com/display.php" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" "-"
如果有人有任何想法,将不胜感激


谢谢

所以我很高兴告诉你我找到了解决问题的方法。 但说实话,我不明白问题的本质

解决方案来自该线程:

仅在ftp_登录()后添加:


感谢您的时间@Martin

,为什么您认为这是由
ftp\u-rawlist
引起的?似乎您必须调试位置。那么您怎么知道呢?我认为它来自ftp\u-rawlist,因为当我用ftp\n列表替换它时,我没有问题。但是ftp\n列表不适合我的需要,因为它只列出文件,而不列出所需的文件夹ems不太可能,除非问题是脚本达到内存限制(由于
ftp\u rawlist
的输出较大)或者脚本执行限制。等等,让我重新确认我以前的说法。你是对的,我使用ftp列表进行了更多的压力测试,实际上它在某个点上做出了相同的反应。爬网的ftp文件夹有一个文本文件和一个文件夹。如果
ftp\u USEPASVADDRESS
ftp\u pasv
是唯一的修复方法,我不理解你的脚本是如何工作的。无论如何,至少现在它可以工作了:)
ftp_set_option($ftp_conn, FTP_USEPASVADDRESS, false); // set ftp option
ftp_pasv($ftp_conn, true); //make connection to passive mode