<?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); ?>
以上就介紹了PHP用cURL從FTP伺服器上下載文件,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。