简体   繁体   English

使用php从第三方ftp服务器压缩和下载

[英]Compress and download from 3rd party ftp server using php

I'm downloading files from 3rd party ftp server using php. 我正在使用php从第三方ftp服务器下载文件。 But file is more then 15mb. 但是文件超过15mb。 So it took more time to download. 因此,下载花费了更多时间。 I have an idea to compress and download on the fly from ftp server. 我有一个想法可以从ftp服务器即时压缩和下载。 Is it possible to do so? 有可能这样做吗?

Thanks in advance. 提前致谢。

You have to download the original file, one way or another. 您必须以一种或另一种方式下载原始文件。 You can zip it with PHP, but only after you download the original file to your server. 您可以使用PHP zip它,但只有在将原始文件下载到服务器后才能zip What you are asking is it the source server can compress it for you, which with FTP is not possible. 您要问的是,源服务器可以为您压缩它,而FTP无法实现。

Consider using CURL to download the file from the FTP server. 考虑使用CURL从FTP服务器下载文件。 It's much more resiliant. 它更具弹性。

$curl = curl_init();
$file = fopen("file.zip", 'w'); ##where you want to save it
curl_setopt($curl, CURLOPT_URL, "ftp://ftp.sunet.se/file.zip"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
curl_exec($curl);
curl_close($curl);
fclose($file);

Source 资源

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

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