In Linux, we use the scp
command to securely copy files and folder between two servers.
The basic syntax of scp
command is as follows:
scp [OPTIONS] [SRC_ADDRS]:[file|directory] [DST_ADDRS]:[file|directory]
where
OPTIONS
: These are different flags/options enabled/disabled during the copy operation.SRC_ADDRS
dan DST_ADDRS
: This is username@ip_address
.[file|directory]
: The file or directory path.We’ll use the following command to copy a file from a remote host to local host.
According to the syntax explained above, let’s assume the following:
username
is remoteuser
ip_address
is 10.12.13.1
/home/Documents/test_doc.txt
/User/educative/Downloads/test_doc_copy.txt
scp remoteuser@10.12.13.1:/home/Documents/test_doc.txt /User/educative/Downloads/test_doc_copy.txt
We’ll use the following command to copy the contents of the directory in a recursive way from a remote host to local host.
According to the above syntax, let’s assume the following:
username
is remoteuser
ip_address
is 10.12.13.1
/home/Documents/test_dir
/User/educative/Downloads
scp -r remoteuser@10.12.13.1:/home/Documents/test_dir /User/educative/Downloads
Free Resources