首页 文章

将文件夹传输到FTP服务器而不迭代所有文件

提问于
浏览
0

我试图使用PHP将整个文件夹传输到FTP服务器 .

现在我正在使用这段代码:

function ftp_copyAll($conn_id, $src_dir, $dst_dir) { 
  if (is_dir($dst_dir)) { 
    return "<br> Dir <b> $dst_dir </b> Already exists  <br> "; 
  } else { 
    $d = dir($src_dir); 
    ftp_mkdir($conn_id, $dst_dir);   
    echo "create dir <b><u> $dst_dir </u></b><br>"; 
    while($file = $d->read()) { // do this for each file in the directory 
      if ($file != "." && $file != "..") { // to prevent an infinite loop
        if (is_dir($src_dir."/".$file)) { // do the following if it is a directory 
          ftp_copyAll($conn_id, $src_dir."/".$file, $dst_dir."/".$file); // recursive part 
        } else { 
          $upload = ftp_put($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY); // put the files 
          echo "creat files::: <b><u>".$dst_dir."/".$file ." </u></b><br>"; 
        } 
      } 
      ob_flush() ; 
      sleep(1);  
    } 
    $d->close(); 
  } 
  return "<br><br><font size=3><b>All Copied  ok </b></font>"; 
}

但是有可能在不迭代文件的情况下传输整个文件夹吗?因为我有大约100个文件,PHP花费了大量的时间进行传输 .

有没有办法提高转移速度?

1 回答

  • 0

    不,普通的FTP服务器不支持其他通用方式 .


    除了您在本地打包文件(zip,gzip等),上传它们并远程解压缩 .

    但是,如果您只有FTP访问权限,则无论如何都无法远程解压缩它们 . 除非FTP服务器明确允许 . 允许您执行任意远程shell命令(通常不允许)或使用专有的“unpack”扩展(很少有服务器支持) .


    FTP协议通常非常低效地传输大量小文件,因为每次文件传输都有很大的开销来打开单独的数据传输连接 .

相关问题