To copy files remotely on Linux using scp
, the basic syntax is:
scp [source file] [username]@[remote host]:[destination]
For example, to copy a file called “file.txt” from your local machine to a remote host called “example.com” in the user’s home directory, you would use the following command:
scp file.txt user@example.com:~/
To copy files remotely on Linux using rsync
, the basic syntax is:
rsync [options] [source file] [username]@[remote host]:[destination]
For example, to copy all files and directories in the local directory “/local/dir” to the remote host “example.com” in the remote directory “/remote/dir”, you would use the following command:
rsync -avz /local/dir/ user@example.com:/remote/dir/
You can also use the -e
option to specify the ssh command that rsync should use to connect to the remote server:
rsync -avz -e "ssh -i /path/to/sshkey" /local/dir/ user@example.com:/remote/dir/
Keep in mind that the scp
command only copies files, while rsync
can also copy directories and has the ability to synchronize the remote and local directories.