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