Site icon TechMesto

PHP Server to Server Transfer Script to Remotely Transfer Files

While Switching Web Hosts, we need to download all our files from the old server and then upload them to the new server. It will not be a problem for ones who only have few MB’s to transfer or ones who have high speed connections which can do the download and upload in minutes. But, if the size of files is Huge and the connection is of average speed, it can consume too much of time. Here, Server to Server Transfer Script comes for the rescue.

Server to Server transfer script allows you to download files from another Server and save it locally on the required server. What the script does is to Fetch the file from the URL provided and then saves it to the local server space. It uses the bandwidth and high speed connection of the server and hence the transfer completes in few minutes without much hassle. Here’s how to use it:

  1. Create a new directory named sst (or anything you wish) on the server on which you wish to transfer the files.
  2. Create a new File named sst.php in the folder created in previous step and paste the following script in it and save the file:
    <html>
        <form method="post">
        <input name="url" size="50" />
        <input name="submit" type="submit" />
        </form>
        <?php
         
        // maximum execution time in seconds
        set_time_limit (24 * 60 * 60);
         
        if (!isset($_POST['submit'])) die();
         
         
        // folder to save downloaded files to. must end with slash
        $destination_folder = 'downloads/';
         
        $url = $_POST['url'];
        $newfname = $destination_folder . basename($url);
         
        $file = fopen ($url, "rb");
        if ($file) {
          $newf = fopen ($newfname, "wb");
         
          if ($newf)
          while(!feof($file)) {
            fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
          }
        }
         
        if ($file) {
          fclose($file);
        }
         
        if ($newf) {
          fclose($newf);
        }
         
        ?>
        </html>
  3. Create a new sub-directory named downloads in the directory created in first step.
  4. Now, just open the sst.php in a web browser by pointing your browser to – http://YourDomain.com/sst/sst.php
  5. If you pointed to the correct URL, a form will open up. Just enter the URL of the file which you wish to download to the server and press Enter.
  6. If everything goes correctly, file will be downloaded and saved in the /sst/downloads/ directory.
Exit mobile version