How to copy files from one hosting server to another directly?

The below example shows how you can copy files from one hosting to another without downloading it on your local machine and using ftp or any other source to upload those files.

This can be done with a simple cron job and trust me its very useful in case you want to quickly copy the files from one server location to another and the file size is your concern.

Steps to copy files from one hosting to another:

1. Please create a zip of all the files that you want to be copied and keep it in your public folder.

You can use your traditional approach in zipping files on the server or you can use the shell with putty to do so.

Here is the command to create a zip file using shell.

tar -czvf name-of-archive.tar.gz ./public_html <hit enter>

Here, . represents the current directory and public_html represents the folder to be archived/zipped.

2. Now, open the cpanel account of the other hosting/server.
3. Locate the Cron Jobs section in the cpanel area.
4. Create a Cron Job with 1 min or 5 mins interval (You can use your email id to get notified when the cron job runs). Please note we have to remove this cron job after it gets executed very first time. So that it do not executes the same command again.

wget /path_on_your_server_where_the_file_has_to_be_copied

5. With the above step you will be able to archived file from one server location to another.
6. Now, you can use the traditional approach to decompress the files or can use the below step to decompress the files using shell (putty).

tar -xzvf ./name-of-archive.tar.gz ./public_html <hit enter>

Hope this example was useful to you.


Related Post


Yuvraj has written 39 articles

"Learn & Share" - I believe in this. What about you?