Transfer File from Server to Server with Curl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jkraft10
Forum Newbie
Posts: 10
Joined: Sun Feb 14, 2010 8:00 pm
Location: Fontana, CA

Transfer File from Server to Server with Curl

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Transfer File from Server to Server with Curl

Post by s.dot »

Better would depend on the circumstances ;d

Other options are the built-in FTP functions and POSTing
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
jkraft10
Forum Newbie
Posts: 10
Joined: Sun Feb 14, 2010 8:00 pm
Location: Fontana, CA

Re: Transfer File from Server to Server with Curl

Post 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
Post Reply