How to transfer files between local/server in Linux

Many current remote connection tools such as XShell or MobaXterm provide upload and download functions. In addition, some Linux terminal commands such as scp and sftp can also implement such functions, and are more flexible and convenient. They can not only meet the needs of Transfer between local and server can also transfer files between two remote servers. Here are some uses of scp.

Copy local files to server

scp localmachine/path_to_the_file username@server_ip:/path_to_remote_directory

Here localmachine/path_to_the_file is the path to the local file, username@server_ip is the username and IP of the server, followed by the path on the server. After running the command and entering the server's login password, the file will be uploaded to the server/path_to_remote_directory location.

What if we want to copy the contents of an entire folder to a remote server? It is also very simple, just add one parameter -r,

scp -r localmachine/path_to_the_file username@server_ip:/path_to_remote_directory

Copy files from server to local

If you want to get the files on the server, you only need to slightly modify the above command:

scp username@server_ip:/path_to_remote_directory local_machine/path_to_the_file

In the same way, if you are getting a folder on the server, you also add the parameter -r:

scp -r username@server_ip:/path_to_remote_directory local_machine/path_to_the_file

Copy files on the server to another server

Suppose we are not logged in to the server and want to copy files from one server to another service:

scp username@server1_ip:/path_to_the_remote_fileusername@server2_ip:/path_to_destination_direcory/

Guess you like

Origin blog.csdn.net/m0_56572447/article/details/131743513