How To Transfer Files From a Remote Server to another Remote Server Using curl
A relatively common situation is requiring the move of a website from one server to another. There are a number ways one can do this.
One could simply download the entire website to a local computer and upload it to the new server or one could use third party FTP tools to log into both servers and transfer files from one to the other,
using their local computer as a sort of “middle man”.
There is another method which is relatively easier which we’ll look at today and that is transferring files across servers using CURL.
Make a file curl.php on server where you want to move file
<?php $strFileName ='filenamefromoneserver.zip'; $url ='http://domain.com/'.$strFileName; $fh = fopen($strFileName, 'w'); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FILE, $fh); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // this will follow redirects curl_exec($ch); curl_close($ch); fclose($fh); ?>