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.