简体   繁体   中英

Compress and download from 3rd party ftp server using php

I'm downloading files from 3rd party ftp server using php. But file is more then 15mb. So it took more time to download. I have an idea to compress and download on the fly from ftp server. 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. What you are asking is it the source server can compress it for you, which with FTP is not possible.

Consider using CURL to download the file from the FTP server. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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