linux USES scp to transfer files from server A to server B

  • 2020-05-10 23:20:32
  • OfStack

scp is a file copy with Security, login based on ssh. It is easy to operate. For example, to transfer the current file copy to another remote host, you can use the following command.

scp /home/daisy/full.tar.gz root@172.19.2.75:/home/root 

You are then prompted for the login password of the root user on the other 172.19.2.75 host, and copy begins.

If you want to do it the other way around, it's also easy to transfer files from the remote host copy to the current system.

scp root@172.19.2.75:/home/root /home/daisy/full.tar.gz 

This paper illustrates the implementation process of file transfer between Linux servers for your reference. The details are as follows

1.1 normal file transfer, no need to connect to server B through proxy service, login server A, execute
scp test.sql user@server-B:path
Instructions: transfer the file test.sql to the server B (user is the user name of server B, server-B is the IP of server B, path is the specified path to receive the file on server B), enter the password of user

1.2 need to access server B via proxy, execute

scp -oProxyCommand='nc -v -xproxy:port %h %p' test.sql user@server-B:path
Note: proxy is the IP of the proxy server, port is the port of the proxy server, enter the password of user

You can also use the sftp command in the same format as above:

sftp -oProxyCommand='nc -v -xproxy:port %h %p' user@server-B port
Note: the last port is the port   of the server B

1.3 transfer files using scp

1) download files from the server
scp username@servername:/path/filename /tmp/local_destination

For example scp codinglog@192.168.0.101: / home kimi/test txt   put 192.168.0.101 / home/kimi/test txt download files to/tmp local_destination
2) upload local files to the server
scp /path/local_filename username@servername:/path    

For example scp var/www/test php   codinglog@192.168.0.101: / var/www/  native/var test/www/directory. php file
Upload to the /var/www/ directory on the server 192.168.0.101
3) download the entire directory from the server
scp -r username@servername:remote_dir/ /tmp/local_dir  

For example: scp-r codinglog@192.168.0.101 /home/kimi/test /tmp/local_dir
4) upload the directory to the server
scp   -r /tmp/local_dir username@servername:remote_dir

Such as:
scp - r test       codinglog@192.168.0.101: / var/www/    test directory to the current directory uploaded to the server/var www/directory

This is the whole content of linux transferring files from the server A to the server B. I hope it will inspire you to learn how to transfer files between the servers of Linux.


Related articles: