Hi Reader's,
Welcome to FindNerd, today we are going to discuss on download file from FTP using curl.
If you want to download files from FTP using curl then you have to follow below code.
Suppose you want to download "filename.xy" file which URL is given below :
ftp://ftp.example.com/filename.xy
Now you have to write below code :
<?php
$curl = curl_init();
$file = fopen("filename.gz", 'w');
curl_setopt($curl, CURLOPT_URL, "ftp://ftp.example.com/filename.xy"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
curl_exec($curl);
curl_close($curl);
fclose($file);
?>
In above code you can replace filename.xy from your file name and also replace the FTP url with your FTP url.
I hope this blog help to you download files from FTP using curl.
Thanks
0 Comment(s)