Curl Learning Notes and summaries (4) Use Curl to download files from FTP and upload files to FTP

Source: Internet
Author: User

Download:

<?PHP$curlobj=Curl_init (); curl_setopt ($curlobj, Curlopt_url, "ftp://192.***.*.***/file name"); curl_setopt ($curlobj, Curlopt_header, 0); curl_setopt ($curlobj, Curlopt_returntransfer, 1); curl_setopt ($curlobj, Curlopt_timeout, 300);//Times out after 300scurl_setopt ($curlobj, Curlopt_userpwd, "User name: Password");//FTP username: password//sets up the output file$outfile=fopen(' Test.txt ', ' WB ');//save to local file namecurl_setopt ($curlobj, Curlopt_file,$outfile);$rtn= Curl_exec ($curlobj); fclose($outfile); if(!curl_errno ($curlobj)){    Echo"RETURN:".$rtn; } Else {  Echo' Curl error: '. Curl_error ($curlobj);} Curl_close ($curlobj);

Upload:

<?PHP$curlobj=Curl_init (); $localfile= ' test.php ';$fp=fopen($localfile, ' R '); curl_setopt ($curlobj, Curlopt_url, "ftp://***.***.***.***/saved file name"); curl_setopt ($curlobj, Curlopt_header, 0); curl_setopt ($curlobj, Curlopt_returntransfer, 1); curl_setopt ($curlobj, Curlopt_timeout, 300);//Times out after 300scurl_setopt ($curlobj, Curlopt_userpwd, "User name: Password");//FTP user name: Passwordcurl_setopt ($curlobj, Curlopt_upload, 1); curl_setopt ($curlobj, Curlopt_infile,$fp); curl_setopt ($curlobj, Curlopt_infilesize,filesize($localfile));$rtn= Curl_exec ($curlobj); fclose($fp); if(!curl_errno ($curlobj)){    Echo"uploaded successfully."; } Else {  Echo' Curl error: '. Curl_error ($curlobj);} Curl_close ($curlobj);

Curl Learning Notes and summaries (4) Use Curl to download files from FTP and upload files to FTP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.