Applicable scenarios | Command | Example |
Transfer files between two Linux servers | scp <Username of the source host>@<IP address of the source host>:<Path of the file to be transferred> <Username of the destination host>@<IP address of the destination host>:<Destination file path> | To transfer files from the ECS instance whose IP address is 192.168.1.104 to the /home/ directory on the ECS instance whose IP address is 192.168.1.105, execute the following command: scp root@192.168.1.104:/test.txt root@192.168.1.105:/home/ |
Upload files from the local machine to a remote server | scp <Local file path> <Username of the remote server>@<EIP of the remote server>:<File path on the remote server> | To upload the local file /home/test.txt to the corresponding directory on the ECS instance whose EIP is 10.x.x.x, execute the following command: scp /home/test.txt root@10.x.x.x:/home/ |
Download files from a remote server to the local host | scp <Username of the remote server>@<EIP of the remote server>:<File path on the remote server> <Local file storage path> | To download the /home/test.txt file from the ECS instance whose EIP is 10.x.x.x to the local /home/ directory, execute the following command: scp root@10.x.x.x:/home/test.txt /home/ |
The parameters. | Description |
-v | Show details. |
-q | Ignore non-error-related output. |
-a | The archive mode, which specifies that files are transferred recursively and all file attributes are preserved, equivalent to -rlptgoD (excluding -H, -A, and -X). |
-r | Process subdirectories recursively. |
-l | Do not process symbolic links (retain symbolic links). |
-p | Retain permission. |
-t | Retain the modification time. |
-g | Retain the group information |
-o | Retain the file owner information. |
-D | Retain the device file information. |
-H | Retain hard links. |
-S | Apply special handling to sparse files to conserve space. |
-z | Compress data during transfer. |
Applicable scenarios | Command | Example |
Copy local files | rsync -avSH <Source file path> <Destination path> | To copy the test.txt file from the /home directory to the /tmp directory, execute the following command: rsync -avSH /home/test.txt /tmp/ |
Copy the contents of the local machine to the remote machine (by using Shell programs such as SSH) | rsync -av <Local file path> <IP address of the remote machine>:<File storage path on the remote machine> | To copy the test.txt file from the /home directory on the local machine to the /tmp directory on the remote machine whose IP address is 192.168.2.65, execute the following command: rsync -av /home/test.txt 192.168.2.65:/tmp/ |
Copy the contents of the remote machine to the local machine (by using Shell programs such as SSH) | rsync -av <IP address of the remote machine>:<File path on the remote machine> <File storage path on the local machine> | For example, to copy the test.txt file from the /tmp directory on the remote machine whose IP address is 192.168.2.65 to the /home directory on the local machine, execute the following command: rsync -av 192.168.2.65:/tmp/test.txt /home/ |
Copy files from the local machine to the remote Rsync server (Rsync transfer) | rsync -av <Local file path> <auth user>@<IP address of the remote server>::<Module name> | To upload the local test.txt file to the test module on the remote machine whose IP address is 192.168.2.65, execute the following command: rsync -av /root/test.txt root@192.168.2.65::test |
Copy files from the remote Rsync server to the local machine (Rsync transfer) | rsync -av <auth user>@<IP address of the remote server>::<Module name> <Local file storage path> | To copy files from the test module of the remote machine whose IP address is 192.168.2.65 to the /home directory of the local machine, execute the following command: rsync -av root@192.168.2.65::test /home/ |
Display the file list of the remote machine (Rsync transfer) | rsync -v rsync://<IP address of the remote server>/<Module name> | To display the file list of the remote machine whose IP address is 192.168.2.65, execute the following command: rsync -v rsync://192.168.2.65/test |
The parameters. | Description |
-g<gateway> | Specify the remote communication gateways of the router. You can specify up to eight remote communication gateways. |
-G<Number of pointers> | Specify the number of source-routing pointers. The value must be a multiple of 4. |
-h | Online help. |
-i<Latency in seconds> | Specify the time interval for transferring information and scanning communication ports. |
-l | Use listen mode to control incoming data. This parameter must be used together with the -p option. |
-n | Use the IP address instead of the domain name server. |
-p<Communication port> | Specify the communication port used by the local host. |
-r | Specify the communication ports for the local and remote hosts. |
-s<Source address> | Specify the IP address for outgoing data packets from the local host. |
-u | Use the UDP transport protocol. |
-v | Display the command execution process. |
-w<timeout duration in seconds> | Specify the connection timeout period. |
-z | Use 0 input/output mode only for scanning communication ports. |