Page 1 of 1
Transfer File from Server to Server with Curl
Posted: Thu Mar 11, 2010 11:40 pm
by jkraft10
Code: Select all
$url = "http://www.example.com/catch/test.zip";
$file = "test.zip";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
set_time_limit(300);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$handle = fopen($file, 'wb');
curl_setopt($ch, CURLOPT_FILE, $handle);
curl_exec($ch);
fclose($handle);
curl_close($ch);
So, this is what I have used in the past. It is transferring the file from the same server the code above is living on to "example.com/catch/".
Is there a better way to transfer a file from one server to another?
Thanks
Re: Transfer File from Server to Server with Curl
Posted: Fri Mar 12, 2010 1:10 am
by s.dot
Better would depend on the circumstances ;d
Other options are the built-in FTP functions and POSTing
Re: Transfer File from Server to Server with Curl
Posted: Fri Mar 12, 2010 10:39 am
by jkraft10
s.dot, thanks for the input. I also thought about posting the contents of the file. I think it is easier to troubleshoot post than curl. I haven't ventured into FTPland with php yet. Maybe some day.
Thanks