Four ways to transfer files between linux servers
- 2020-05-10 23:20:53
- OfStack
This article has Shared 4 ways of transferring files between linux servers for your reference. The details are as follows
1. scp
[advantages] simple and convenient, safe and reliable; Support speed limit parameter
[disadvantage] does not support exclude directory
[usage]
scp is secure copy, which is used for remote file copying. The data transfer USES ssh, and it USES the same authentication method as ssh, providing the same security guarantees.
Command format:
scp [ parameter ] < Source address (username) @IP Address or hostname) >:< The file path > < Destination address (username) @IP Address or hostname) >:< The file path >
For example:
scp /home/work/source.txt work@192.168.0.10:/home/work/ # The local source.txt Copy the file to 192.168.0.10 On a machine /home/work directory
scp work@192.168.0.10:/home/work/source.txt /home/work/ # the 192.168.0.10 On a machine source.txt Copy the file to the local /home/work directory
scp work@192.168.0.10:/home/work/source.txt work@192.168.0.11:/home/work/ # the 192.168.0.10 On a machine source.txt Copy the file to 192.168.0.11 The machine's /home/work directory
scp -r /home/work/sourcedir work@192.168.0.10:/home/work/ # Copy the folder, add -r parameter
scp -r /home/work/sourcedir work@www.myhost.com:/home/work/ # Use the hostname
scp -r -v /home/work/sourcedir work@www.myhost.com:/home/work/ # Show details, plus -v parameter
2. rcp
【 summary 】
The target host needs to turn on the rcp function and set the permissions of rcp: add the source host to the list of trusted hosts, otherwise you cannot use rcp on the source host to remotely copy files to the target host.
3. wget
[advantages] simple and convenient, support exclude directory, support speed limit parameters
can only download files or folders locally from a remote machine, and the remote machine needs to support ftp services (e.g., start proftpd). With many parameters, it is more complex than scp in use
1. is a teacher
wget is a free tool for automatically downloading files from the Internet. It supports downloading through HTTP, HTTPS and FTP, the three most common TCP/IP protocols, and can use HTTP agent.
Command format:
wget [parameter] ftp://
<
Target machine ip or hostname
>
/
<
The absolute path to the file
>
#proftpd format
For example:
wget ftp://192.168.0.10//home/work/source.txt # from 192.168.0.10 Copy on folder source.txt
wget ftp://www.myhost.com//home/work/source.txt # Use the hostname
wget -nH -P /home/work/ ftp://www.myhost.com//home/work/source.txt # Specify the local save path, using the parameter" -P Path "or" --directory-prefix= The path "; -nH, --no-host-directories The host directory is not created
wget -r -l 0 -nH -P /home/work/ ftp://www.myhost.com//home/work/sourcedir # Recursive download sourcedir Directory, using parameters -r ; parameter -l, --level=NUMBER Maximum recursion depth (inf or 0 On behalf of the infinite ).
wget --cut-dirs=3 -r -l 0 -nH -P /home/work/ ftp://www.myhost.com//home/work/sourcedir #- parameter -cut-dirs=NUMBER ignore NUMBER Layer remote directory, in this example myhost On the sourcedir The directory is saved locally work Directory.
wget --limit-rate=200k --cut-dirs=3 -r -l 0 -nH -P /home/work/ ftp://www.myhost.com//home/work/sourcedir #- parameter --limit-rate=RATE Limit the download input rate
wget --limit-rate=200k --cut-dirs=3 -r -l 0 -nH -P /home/work/ -X /home/work/sourcedir/notincludedir ftp://www.myhost.com//home/work/sourcedir # Exclude path use -X parameter
wget -q --limit-rate=200k --cut-dirs=3 -r -l 0 -nH -P /home/work/ -X /home/work/sourcedir/notincludedir ftp://www.myhost.com//home/work/sourcedir # parameter -q Represents quiet mode, no output; The default is -v , redundancy mode
4. rsync
[advantages] powerful function, operation is similar to scp, support exclude directory, support speed limit parameters; Local replication is also supported.
No faults for the time being
1.
rsync is a data image backup tool based on the unix system, as can be seen from the naming of the software -- remote sync. It operates like scp, but is much more powerful than scp. When you use a double colon to split the hostname and file path, you use the rsync server, which is not covered here.
Command format:
rsync [parameter]
<
Source address (username @IP address or hostname)
>
:
<
The file path
>
<
Destination address (username @IP address or host name)
>
:
<
The file path
>
Example:
rsync /home/work/source.txt work@192.168.0.10:/home/work/ # The local source.txt Copy the file to 192.168.0.10 On a machine /home/work directory
rsync work@192.168.0.10:/home/work/source.txt /home/work/ # the 192.168.0.10 On a machine source.txt Copy the file to the local /home/work directory
rsync work@192.168.0.10:/home/work/source.txt work@192.168.0.11:/home/work/ # the 192.168.0.10 On a machine source.txt Copy the file to 192.168.0.11 The machine's /home/work directory
rsync -r /home/work/sourcedir work@192.168.0.10:/home/work/ # Copy the folder, add -r parameter
rsync -r /home/work/sourcedir work@www.myhost.com:/home/work/ # Use the hostname
rsync -r -v /home/work/sourcedir work@www.myhost.com:/home/work/ # Show details, plus -v parameter
rsync -r -v --exclude sourcedir/notinclude /home/work/sourcedir work@www.myhost.com:/home/work/ # Exclude subdirectories, note: --exclude The following path can not be an absolute path, must be a relative path to be able to, otherwise can not match, will not be excluded.
The above is the entire content of this article, I hope to help you with your study.