December 21, 2024

How to transfer files/folder from one Linux server to another

Suppose you want to backup or transfer files from one remote server to another you can do it simply by using scp. Let me brief you about SCP.

SCP stands for secure copy (remote file copy program).

scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). scp will ask for passwords or passphrases if they are needed for authentication.

COPY CODE SNIPPET

File names may contain a user and host specification to indicate that the file is to be copied to/from that host. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:’ as host specifiers. Copies between two remote hosts are also permitted.

Enough of theory stuff, let’s see the example:

Suppose you want to transfer files/folder from 12.34.56.789 to 88.12.98.980. Therefore first login to the server 88.12.98.980 and run the following command as follows:-

scp -r root@12.34.56.789:/var/www/html.zip /var/www/html/

where

-r = Recursively copy entire directories. Note that scp follows sym‐bolic links encountered in the tree traversal.

root = User of that machine.

12.34.56.789 = Ip of the server where the data exists.

/var/www/html.zip = File that resides on 12.34.56.789 server.(from where u will transfer)

/var/www/html = Directory of 88.12.98.980 server where the files will be copied.

For the server which doesn’t have the default port 22 run the following command:

scp -r -P1234 root@88.12.98.980:/var/www/html.zip /var/www/html/

Done Enjoy!!?

Vedant Kumar

Currently I'm working as an Implementation Engineer, Started my career as an System Administrator - Linux. Additionally loves to explore new technologies and research about new open-source software that ease the development cycle.

View all posts by Vedant Kumar →

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.

close

Ad Blocker Detected!

VEDANT EXPLAINS
We've noticed that you are using an ad blocker. Advertising helps fund our server cost and keep it truly independent. It helps to build our content creator team. So please disable your ad blocker, and help us to keep providing you with free- great content - for free. Thank you for your support.

Refresh