Copying Files Between Different Hosts on Linux#
Prerequisites#
The two target hosts for file copying must be able to communicate. The local end must have scp installed.
SCP Command#
Command format: scp [source file path] [target file path]
Usage:
usage: scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file]
[-J destination] [-l limit] [-o ssh_option] [-P port]
[-S program] source ... target
1. Copying Files from Local End to Target End#
scp /root/a [email protected]:/root/b
Where 'a' and 'b' are the file names and can be different.
2. Copying Files from Target End to Local End#
scp [email protected]:/root/a /root/b
3. Note#
If copying a folder, add -r after scp.
Since scp is based on the ssh port, it transfers files using the default local port to the remote port via ssh. If the ssh ports on both ends are different or have port restrictions, you need to specify them again by adding -P after the scp command, where 'P' must be capitalized. Refer to the scp usage.
4. Unusual Usage#
Can you copy files from a remote end to another remote end? Yes.
scp [email protected]:/root/a [email protected]:/root/b