简体   繁体   English

在php中使用ftp_get感到困惑

[英]Confused using ftp_get in php

Im confused by an estate agency vebra import script that worked fine before it was moved to a different server however now this seems to not work at all. 我感到困惑的是一个房地产代理vebra导入脚本,它在移动到另一台服务器之前运行良好但是现在这似乎根本不起作用。

Does anyone have any idea why i would get the following warnings... 有谁知道为什么我会得到以下警告......

Warning: ftp_get() [function.ftp-get]: Opening data channel for file transfer. 警告:ftp_get()[function.ftp-get]:打开文件传输的数据通道。 in /home/username/public_html/includes/cron/import/vebra-import.php on line 37 在第37行的/home/username/public_html/includes/cron/import/vebra-import.php中

Warning: ftp_get() [function.ftp-get]: Transfer OK in /home/username/public_html/includes/cron/import/vebra-import.php on line 37 警告:ftp_get()[function.ftp-get]:在第37行的/home/username/public_html/includes/cron/import/vebra-import.php中转移确定

here is the ftp connection code: 这是ftp连接代码:

  $ftp = ftp_connect($ftp_host, 21) or die("FTP Connection Error");

  ftp_login($ftp, $ftp_user, $ftp_pass) or die("Can't Connect to FTP");

  $ftpdir = ftp_nlist($ftp, "/");


  if(!empty($ftpdir) && count($ftpdir) > 0) {

  foreach($ftpdir as $ftpfile) {

      if(preg_match("/\.txt$/", $ftpfile)) {
          $getfile = ftp_get($ftp, $csv_dir.$ftpfile, $ftpfile, FTP_BINARY);
          if($getfile){
              $downloaded++;
          }
          $total++;

      }

  }

  }
  ftp_close($ftp);

Furthermore, it seems to be intermittent, and sometimes this executes successfully other times it fails with the above errors. 此外,它似乎是间歇性的,有时这会成功执行,有时它会因上述错误而失败。

Your server is not in a passive mode, and add this code to process: 您的服务器未处于被动模式,并添加此代码以进行处理:

ftp_pasv($ftp, true);

For more information look at passive mode on php.net: http://php.net/manual/en/function.ftp-pasv.php Passive mode uses the data initiated by the client rather than the server. 有关更多信息,请参阅php.net上的被动模式: http//php.net/manual/en/function.ftp-pasv.php被动模式使用客户端而不是服务器发起的数据。 So this is why you can't put on server. 所以这就是你不能穿上服务器的原因。 If this is not set it will fail. 如果未设置,则会失败。

NOTE: Set ftp_pasv() function after ftp_login() function. 注意:在ftp_login()函数后设置ftp_pasv() ftp_login()函数。

After using ftp_pasv () the problem was still occurring. 使用ftp_pasv()后问题仍然存在。 I found out that the number of requests to the server caused a problem with the firewall (I used a foreach() loop to scroll through multiple files). 我发现服务器的请求数导致防火墙出现问题(我使用foreach()循环滚动浏览多个文件)。 Because I did not have permission to modify the firewall rules, I added a sleep () in my script between the requests. 因为我没有权限修改防火墙规则,所以在我的脚本中在请求之间添加了sleep()。

This is how i fixed the warning. 这就是我修复警告的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM