Php uses curl to download ftp files,
The example in this article shows how to download ftp files in php for your reference. The details are as follows:
I don't know why the normal ftp_get function is very slow to download files, but the ftp client is very fast to download, so the curl download method is changed, and the speed is normal.
Function file_upload ($ ftpIp, $ ftpUser, $ ftpPwd, $ path, $ fileSavePath) {$ curlobj = curl_init (); // initialize // input the target ftp file, for example, 'ftp: // 192.168.3.1/test/1.jpg 'curl_setopt ($ curlobj, CURLOPT_URL, "ftp ://". $ ftpIp. "/". $ path); curl_setopt ($ curlobj, CURLOPT_HEADER, 0); // No output header curl_setopt ($ curlobj, CURLOPT_RETURNTRANSFER, 0 ); // time out after 300 s curl_setopt ($ curlobj, CURLOPT_TIMEOUT, 2000); // timeout // you can use this function to set the ftp user name and password, which is not required ! Curl_setopt ($ curlobj, CURLOPT_USERPWD, $ ftpUser. ':'. $ ftpPwd); $ outfile = fopen ($ fileSavePath, 'W + '); // name of the file saved to the 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 opened locally, delete return false ;}}
It is normal to test the downloading of small files, but if the network speed is slow, an ftp timeout error will be reported when downloading large files. At present, I still don't know where to configure the problem or what the problem is.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.