(PHP)用cURL从FTP服务器上下载文件

时间:2021-06-30 17:49:58
<?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);

?>