Moving large file from one server to another server without downloading locally

Monday, July 11, 2011 16:07
Posted in category PHP

Here is the simple script to copy large file from one server to another server without downloading it to local machine.

<?php
    $in = fopen("http://xyz.com/backup.tar.gz", "rb");
    $out = fopen("backup.tar.gz", "w+");
    echo pipe_streams($in, $out);

    function pipe_streams($in, $out)
    {
        $size = 0;
        while (!feof($in)) $size += fwrite($out,fread($in,8192));
        return $size;
    }
?>

Create a download.php in your destination server and change the filename to be downloaded and created.
It will avoid user’s bandwidth and time and it is the easiest way to copy the large backup files from one server to another server, while changing the hosting server.

You can leave a response, or trackback from your own site.

One Response to “Moving large file from one server to another server without downloading locally”

  1. Anton says:

    July 26th, 2011 at 6:16 pm

    Nice, short and working solution!

    Transmitted 793 742 697b file less then a minute.

    Thanks!

Leave a Reply

*