PHP uses Curl to implement FTP file Download function method

Source: Internet
Author: User
Tags ftp file ftp client
This article mainly for you in detail the PHP using Curl to achieve FTP file download function, with a certain reference value, interested in small partners can refer to

Specific content is as follows

I do not know why the normal ftp_get function to download the file speed is particularly slow, but the FTP client download quickly, so the download method for curl, the speed is normal

function File_upload ($ftpIp, $ftpUser, $FTPPWD, $path, $fileSavePath) {  $curlobj = Curl_init ();//Initialize  // The destination file for incoming FTP, such as ' Ftp://192.168.3.1/test/1.jpg '  curl_setopt ($curlobj, Curlopt_url, "ftp://". $ftpIp. " /". $path);  curl_setopt ($curlobj, curlopt_header,0);//Output HEADER  curl_setopt ($curlobj, curlopt_returntransfer,0);   Time Out after 300s curl_setopt ($curlobj, curlopt_timeout,2000);//timeout period  //through this function to set the FTP user name and password, no settings do not need!   curl_setopt ($curlobj, Curlopt_userpwd, $ftpUser. ': ' $ftpPwd);  $outfile = fopen ($fileSavePath, ' w+ '); FileName saved to local file   curl_setopt ($curlobj, Curlopt_file, $outfile);  $rtn = curl_exec ($curlobj);  if (Curl_errno ($curlobj)) {    writelog (' Curl Error: '. Curl_error ($curlobj));  }  Fclose ($outfile);  Curl_close ($curlobj);   if ($rtn = = 1) {    return true;   } else{    unlink ($fileSavePath);//If the download fails, but the file is open locally, so remove    return false;   }}

Test download small files is normal, but if the speed is very slow, download large files, will be reported an FTP timeout error, is still not know where to configure the problem, or what the problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.