PHP: Using Curl to access FTP

Source: Internet
Author: User

today to do FTP upload. I want to use PHP's own FTP function to implement, the results found that this module is not compiled, recompile PHP is too cumbersome to use other ways to achieve it
  FTP upload
if(isset($_post[' Submit '])) {    if(!Empty($_files[' Upload '] [' Name '])) {        $ch=Curl_init (); $localfile=$_files[' Upload '] [' Tmp_name ']; $fp=fopen($localfile, ' R '); curl_setopt ($ch, Curlopt_url, ' Ftp://ftp_user:[email protected]/'.$_files[' Upload '] [' Name ']); curl_setopt ($ch, Curlopt_upload, 1); curl_setopt ($ch, Curlopt_infile,$fp); curl_setopt ($ch, Curlopt_infilesize,filesize($localfile)); Curl_exec ($ch); $error _no= Curl_errno ($ch); Curl_close ($ch); if($error _no= = 0) {            $error= ' File uploaded succesfully. '; } Else {            $error= ' File upload error. '; }    } Else {        $error= ' Please select a file. '; }}
Download from FTP
$curl=curl_init ();$target _ftp_file= ' Ftp://192.168.1.12:/filepath/target.txt ';//Full pathcurl_setopt ($curl, Curlopt_url,$target _ftp_file); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_verbose, 1); curl_setopt ($curl, CURLOPT_FTP_USE_EPSV, 0); curl_setopt ($curl, Curlopt_timeout, 300);//Times out after 300scurl_setopt ($curl, Curlopt_userpwd, "User_name:password");//FTP username: password//sets up the output file$target _path= './data ';if(Is_dir($target _path)) {    $outfile=fopen($target _path. ‘/‘ . Dest.txt); curl_setopt ($curl, Curlopt_file,$outfile); $info= Curl_exec ($curl); fclose($outfile); $error _no= Curl_errno ($curl); Curl_close ($curl);}

PHP: Using Curl to access 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.