不能下载使用PHP的FTP一些文件 [英] Cant download some files with PHP FTP

查看:204
本文介绍了不能下载使用PHP的FTP一些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个PHP脚本,通过FTP下载文件和文件夹,这样我可以在特定条件下的备份。但是,这不是下载的所有文件。它是从我们的服务器下载一些图片。我无法理解有什么错图像的其他休息。他们是所有国家的国旗都小图像。他们是相同的大小。如果我从多个根级别下载,它下载其他文件。但是,它究竟是从co.png文件停止。

I wrote a php script to download files and folders through FTP so that i can take backups with certain conditions. But, it's not downloading all files. It's downloading some images from our server. I cant understand what's wrong with other rest of the images. They're all small images of flags of all countries. They're same size. If i download from more root level, it downloads other files. But, it exactly stops from co.png file.

下面是链接(的 http://robi123.com/flags.zip )下载我试图使用PHP FTP下载,图像文件

Here is the link (http://robi123.com/flags.zip) to download the image files I'm trying to download using PHP FTP.

我知道这个脚本可能需要的其它改进或其他下载大文件时也被困在其他步骤。我需要帮助解决这个问题现在。什么是我的脚本不下载其他的图像? PHP的警告附有这个问题。我已经多了一个主意,试图执行RAW FTP命令。忽略RAW FTP命令的code。但是ftp下载的所有其他方法(ftp_get,ftp_nb_get和)都陷入同样的​​事情,同样的警告。但你可以建议任何方式。

I know this script may need other improvements or get stuck in other steps too when downloading other large files. I need help to fix this problem for now. What's my script not downloading the other images? The warning of php is attached with this question. I've one more idea to try executing RAW FTP commands. Ignore the code of RAW FTP command. But all the other methods (ftp_get, ftp_nb_get and ) of ftp download are stuck in same thing and same warning. But you can advise any way.

下面是我的code:

<?php
set_time_limit(0);
ini_set('xdebug.max_nesting_level', "100000000000000000000000");

$ftp_server = "";
$ftp_user    = "";
$ftp_pass = "";

$ftp_conn   = ftp_connect($ftp_server);
$ftp_login   = ftp_login($ftp_conn, $ftp_user, $ftp_pass);

ftp_set_option($ftp_conn, FTP_TIMEOUT_SEC, 10000000);

ftp_set_option($ftp_conn, FTP_AUTOSEEK, true);

ftp_pasv($ftp_conn, true);

if ((!$ftp_conn) || (!$ftp_login)) {
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user<br />";
} else {
    echo "Connected to $ftp_server, for user $ftp_user<br />";
}


echo getcwd()."<br />" ;

function download($ftp_conn,$local_folder,$remote_folder){

     if($local_folder !=""){
     chdir($local_folder);
     }
     echo getcwd()."<br />" ;

     ftp_chdir($ftp_conn,$remote_folder);

     $files_folders = ftp_nlist($ftp_conn, ".");

     foreach($files_folders as $temp){

      if ($temp == '.' OR $temp == '..'){ 
      continue;
      }
      if(ftp_is_dir($ftp_conn,$temp)){
      //echo "$temp<br>";

      @mkdir($temp);

      echo "Folder: ".$remote_folder."/".$temp."<br />";

      download($ftp_conn,$temp,$remote_folder."/".$temp);

      }else{
      ftp_get($ftp_conn, $temp, $temp, FTP_BINARY);
      //ftp_nb_get($ftp_conn, $temp, $temp, FTP_BINARY); 

      /*

        $ret = ftp_nb_get($ftp_conn, $temp, $temp, FTP_BINARY);
        while ($ret == FTP_MOREDATA) {

        $ret = ftp_nb_continue($ftp_conn);
        }
        if ($ret != FTP_FINISHED) {
        echo "There was an error downloading the file";
        exit(1);
        }

      $command = "RETR $remote_folder/$temp";
      $result = ftp_raw($ftp_conn, trim($command));  
      print_r($result);
       */
      echo "File: $temp<br />";

      }

     }

     chdir("..");
     ftp_chdir($ftp_conn, "..");

     return;

}

function ftp_is_dir($ftp_conn,$dir) {
  if (@ftp_chdir($ftp_conn, $dir)) {
    ftp_chdir($ftp_conn, '..');
    return true;
  } else {
    return false;
  }
}

download($ftp_conn,"data","/public_html/c4smod/traffic/Img/Flags/");

?>

推荐答案

我已经找到了问题。我下载了几个图像后,我的脚本只需要重新连接到服务器并下载图像的其余部分。所以,我刚才添加附加条件,以检查是否FTP功能失败,它们会重新连接并重新保存下载文件和图像。我没有尝试强烈进一步查找并知道FTP会话或超时多久存在,或者,如果这些问题都涉及到我的脚本。

I have found the problem. After I downloaded several images, my script just needs to reconnect to server and download the rest of the images. So, i just added additional conditions to check if ftp functions fails and they get reconnected and retry to keep downloading files and images. I did not try strongly to find further and know how long a ftp session or timeout exists or if these issues are related to my script.

这篇关于不能下载使用PHP的FTP一些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆