We Need Website

Blog

  • WordPress
  • Hosting
  • Server
  • How to
  • Applications

Server to Server File Transfer PHP Script, How to Copy Files from Remote Location

Posted by Praan Kumar Leave a Comment

Today we have come with a solution to the problem of transferring files from another host. Generally when you download the files to your computer and later upload the files to a new server require too much time. Moreover, your WIFI/router or mobile data is wasted.  To overcome this issue, we are providing you with the PHP script to remotely copy files within your web hosting. Copying files from one server to server is faster than uploading from your computer.

Server to Server File Transfer PHP Script Installation

Follow the below steps to install the PHP script in your hosting. It’s a simple script consists of two files. If you can’t implement, we will provide the download links at the bottom.

Step 1: Create Destination/Installation Folder

First, decide where you want to download the files. It can be the root directory i.e. public_html or /download something else.

Step 2: Installing the Script

Create a filename called, “transfer.html” on the destination folder or on your Desktop and paste the following code-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Transfer File PHP - Transfer file from another server (php script)</title>
    <style type="text/css">
        body{
            font-family: arial;
            font-size: 14px;
            padding: 0;
            margin: 0;
            text-align: center;
        }
        h3{
            text-align: center;
        }
        .container{
            width: 600px;
            margin: 100px auto 0 auto;
            max-width: 100%;
        }
        label{
            font-weight: bold;
            margin: 10px 0;
        }
        input[type="text"]{
            border: 1px solid #eee;
            padding: 10px;
            display: block;
            margin: 10px auto;
        }
        input[type="submit"]{
            padding: 10px 20px;
            display: block;
            margin: 10px auto;
            border: 2px solid green;
            background: #fff;
        }
        .copyright{
            position: fixed;
            bottom:0;
            background: #333;
            color: #fff;
            width: 100%;
            padding: 10px 20px;
            text-align: center;
        }
        .copyright a{
            color: #eee;
        }
    </style>
</head>
<body>
    <div class="container">
        <h3>Transfer File PHP - Transfer file from another server (php script)</h3>
        <form action="copy.php" method="post">
            <label for="remote_file">Locate the File</label> <br>
            <input type="text" id="remote_file" name="remote_file" value="" placeholder="Enter URL of the file" />
            <input type="submit" value="Transfer" />
        </form>
    </div>

</body>
</html>

 

Now, within the same directory, create another filename called, “copy.php” and paste the below code-

<?php
/**
 * Transfer Files Server to Server using PHP Copy
 * @link https://weneedwebsite.com/blog/server-to-server-remote-file-transfer/
 */

/* Source File URL */
$remote_file_url = $_POST['remote_file'];

/* New file name and path for this file */
$local_file = 'files.zip';

/* Copy the file from source url to server */
$copy = copy( $remote_file_url, $local_file );

/* Add notice for success/failure */
if( !$copy ) {
    echo "Opps! Failed! Something went wrong to copy the $file...\n";
}
else{
    echo "Hurraaah! File successly Copied as files.zip ...\n";
}

?>

 

Step 3: Transfer the Files

You have successfully installed the PHP file transfer script. Now, to transfer the file locate the filename transfer.html. The window for transferring files looks like below-

file transfer script frontend

Now, on the form, enter your remote filename. Then click on Transfer.

After a successful file copied it will display a dialogue as,

“Hurraaah! File successfully Copied as files.zip … “.

If it fails then say as,

“Oops! Failed! Something went wrong to copy the … “.

Download the Script

Important Note:

Now rename the file called “files.zip” to the previous filename extension, as we have just copied the file from a remote location to the local folder and haven’t compressed the file.

The PHP file transfer script here copies the files from the remote server only a single file at once. So, you must combine those files to download at once. You can learn below the articles for your help.

  • FTP ZileZilla Compress Script
  • FTP ZileZilla Extractor Script
Share this

Filed Under: Coding, How to guide

Leave a Reply Cancel reply

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

Recent Posts

  • 5 Top Marketplaces To Sell Domain & Websites
  • Black Friday Web Hosting Deals 2020 Offer, Discount, Coupon, Promocode
  • Grow your Business & Sales with e-Storekeeper. Create a Digital Store Online
  • Top 7 Keyword Research Tools For SEO for 2020-21
  • Top 10 Best Free Online HTML Table Generator/ Editors

Recent Comments

  • Mr S7jk on How to Setup Freenom Domain (.tk, .ml, .cf, .ga, .gq) on Blogger Platform?
  • Sarrah on List of Instagram Web Viewer Script | How to Check Profile without Login
  • Praan Kumar on Step by Step Guide How to Install WordPress on Subdirectory on Cloudways
  • Faiz Alias on Step by Step Guide How to Install WordPress on Subdirectory on Cloudways
  • Joe on How to Setup Freenom Domain (.tk, .ml, .cf, .ga, .gq) on Blogger Platform?

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Copyright © 2021 We Need Website | Privacy Policy . About Us . Contact Us

Login