A Simple Server-to-Server File Transfer Script (PHP)

I’ve used this little script quite a bit while moving servers, and it’s saved me tons of time. It allows you to transfer large files from one server to another by breaking up the file into 1MB pieces to avoid memory limits. There seems to be a 2GB maximum on transfer sizes.

To use it, simply change the variable $path to a relative path on your new server where you want the file to be saved to, change the variable $url to the web-accessible location of the file on the old server, and upload and run the script on your new server.

set_time_limit(0); //Unlimited max execution time
$path = 'newfile.zip';
$url = 'http://example.com/oldfile.zip';
$newfname = $path;
echo 'Starting Download!<br>';
$file = fopen ($url, "rb");
if($file) {
	$newf = fopen ($newfname, "wb");
		while(!feof($file)) {
			fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
			echo '1 MB File Chunk Written!<br>';
if($file) {
if($newf) {
echo 'Finished!';

38 Thoughts on “A Simple Server-to-Server File Transfer Script (PHP)

  1. anon on March 6, 2013 at 1:28 AM said:

    Informative article, just what I was looking for.

  2. Kinjalk Tripathi on June 5, 2013 at 11:23 AM said:

    Very nice,Simple and Lite script..

    It saved my lot of time . It transferred ~700 MB data with in Less than one minute

  3. nice script, thanks

  4. sathish on January 9, 2014 at 7:30 AM said:

    its nice but i need to run script from source

    can you send that script

  5. Thanks alot, very good script. another script:

  6. I am using this for 3.5 gb file but this not work for me. what can i do for transferring 3.5 gig website to another hosting. the first hosting hasn’t cpanel.

  7. I try to move 100mb files to another server and its worked in a few seconds..

  8. Great script!

    How exactly are the 1024 and 8 determined? For a file under 1MB, it will write about 20 lines of “1 MB File Chunk Written!”

  9. Thanx Paulin ..
    i’m using your scripts .. amazing script

  10. wow … nice it’s working … thank you ! :3

  11. If the file is less than 1MB then we can reduce the size of chunks. Will it effect to the transferring speed (time)? and on server’s busyness 😉
    I think you can reply because you have written this short and nice script 🙂

  12. Yuvraj Khavad on July 10, 2014 at 6:17 AM said:

    Thank you for your script……..

    We can say that it is a time saving mechanisms…..my 50MB file transferred just in 15 seconds …

    Keep it up dude…..

    Thanks again……

  13. Muhammad on July 18, 2014 at 4:51 AM said:

    Thank you,

    Simple and very useful script, it saved a lot of time

  14. Jamie Milnes on July 24, 2014 at 11:41 AM said:

    Awesome work Justin!

  15. if the newfile uses no path, like the sample, so it means the downloaded file will be placed at the same location as the php file right? because unlike the other, i can’t make this script run on my server 🙁

  16. Thank you for this. Have used it many times in the past. Has saved me a lot of work and given me lots of spare time to idle while working. Much appreciated.

  17. I have no idea how to say Thank You! You did awesome brother 😀

    Nice & Flexible to use your File Transferring Script.

  18. Thanks you. the script is working.

  19. I want to cry :D, thanks a lot. It saves me a lot of time. Thank you so much bro!

  20. Great man…. Really Useful…

  21. Sameer on May 6, 2015 at 3:11 PM said:

    ohhhh my god! Bro you save my life… many many thanks to you. Your script worth $$100 million $$. you saved my lot of time…really salute to you! 🙂

  22. Awesome!! it saved my 5 hours. Thank you for this script

  23. Juned Zaman on February 23, 2016 at 12:44 AM said:

    Thanks a lot brother, You have done a tremendous job.

  24. Gulshan kumar on May 6, 2016 at 2:42 AM said:


    I have used above script to transfer 800 MB of files but after 500MB of transfer we are getting error “Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.”

    Do you have any idea to transfer big files through above script

    Thanks in Advance.

  25. suhail javaid on May 6, 2016 at 8:55 AM said:


  26. thanks, work it.

  27. Wow!!! Love it.. It save my internet data and time too…. thanks buddy for sharing this useful script.

  28. that is great sir its for very easy and powerful… again thanks
    i need two more scripts any body help me
    1. how can i transfer more than 2 GB, very big file like 14GB size
    2. how to transfer torrent data in my hosting site server? i mean same as this php scrip can i put any torent in my c panel server?

  29. great aritcles, thanks for share it

  30. DrLightman on January 11, 2017 at 5:46 PM said:

    Very useful snippet but contains some inaccuracies:

    1024 * 8 = 8192 = 8 kB

    Whereas for 1 MB you should have used:

    1024 * 1024 = 1048576 = 1 MB

  31. Nice script, thank you

  32. i upload my folder in remote server in zip form now i am trying to upload my php script file which will extract my zip folder on that location.
    but when i upload my php file. this executed itself and error occur.

    please help me to fix this error

    how to upload my project and unzip that folder with php code

  33. Nice article. many many thanks for information

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation