Home > Backend Development > PHP Tutorial > PHP uses cURL to download files from FTP server

PHP uses cURL to download files from FTP server

WBOY
Release: 2016-07-29 09:12:07
Original
1520 people have browsed it
<?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(&#39;fuck.mkv&#39;,&#39;wb&#39;);  //保存到本地文件的文件名
curl_setopt($curlobj,CURLOPT_FILE,$outfile);

$rtn = curl_exec($curlobj);
fclose($outfile);

if(!curl_errno($curlobj)){
    echo "RETURN: ".$rtn;
}else{
    echo &#39;Curl:error: &#39;.curl_errno($curlobj);
}

curl_close($curlobj);

?>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template