Home >Backend Development >PHP Tutorial >PHP uses cURL to download files from FTP server
<?php /** * 用cURL从FTP服务器上下载文件 * Created by PhpStorm. * User: Ollydebug * Date: 2015/11/12 * Time: 15:52 */ $curlobj = curl_init(); curl_setopt($curlobj,CURLOPT_URL,"ftp://172.19.71.63/Flipped.2010.BluRay.720p.DTS.x264-CHD.sample.mkv"); curl_setopt($curlobj,CURLOPT_HEADER,0); curl_setopt($curlobj,CURLOPT_RETURNTRANSFER,0); //time out after 300s curl_setopt($curlobj,CURLOPT_TIMEOUT,500); //通过这个函数设置ftp的用户名和密码,没设置就不需要! //curl_setopt($curlobj,CURLOPT_USERPWD,":"); //sets up the output file $outfile = fopen('fuck.mkv','wb'); //保存到本地文件的文件名 curl_setopt($curlobj,CURLOPT_FILE,$outfile); $rtn = curl_exec($curlobj); fclose($outfile); if(!curl_errno($curlobj)){ echo "RETURN: ".$rtn; }else{ echo 'Curl:error: '.curl_errno($curlobj); } curl_close($curlobj); ?>
The above introduces how PHP uses cURL to download files from an FTP server, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.