scp

On ubuntu/debian for example, the openssh-client package provides the scp program.
$ dpkg -L openssh-client | grep scp
/usr/bin/scp
/usr/share/man/man1/scp.1.gz

So if you are "sending" file from your local machine to a remote machine (uploading) the syntax would look like this
$ scp ~/my_local_file.txt user@remote_host.com:/some/remote/directory

When copying file from remote host to local host (downloading), its looks just the reverse
$ scp user@remote_host.com:/some/remote/directory ~/my_local_file.txt

The verbose output would then indicate the exact point where the program ran into issues.
$ scp -v ~/test.txt root@192.168.1.3:/root/help2356.txt

Multiple files can be specified separated by a space like this
$ scp foo.txt bar.txt username@remotehost:/path/directory/

To copy an entire directory from one host to another use the r switch and specify the directory
$ scp -v -r ~/Downloads root@192.168.1.3:/root/Downloads

Scp can copy files from 1 remote host to another remote host as well.
$ scp user1@remotehost1:/some/remote/dir/foobar.txt user2@remotehost2:/some/remote/dir/
 All you need to do is use the C option to enable compression. The files are compressed on the fly and decompressed on the destination.
$ scp -vrC ~/Downloads root@192.168.1.3:/root/Downloads
use the l option to limit the maximum speed in Kbit/s.
$ scp -vrC -l 400 ~/Downloads root@192.168.1.3:/root/Downloads
particular port number using the '-P' option.
$ scp -vC -P 2200 ~/test.txt root@192.168.1.3:/some/path/test.txt

you would need to specify the identity file which contains the private key. This option is directly passed to the ssh command and works the same way.
$ scp -vCq -i private_key.pem ~/test.txt root@192.168.1.3:/some/path/test.txt

Scp by default uses the AES cipher/encryption. Sometimes you might want to use a different cipher. Using a different cipher can speed up the transfer process. For example blowfish and arcfour are known to be faster than AES (but less secure).
$ scp -c blowfish -C ~/local_file.txt username@remotehost:/remote/path/file.txt

Although scp is very efficient at transferring file securely, it lacks necessary features of a file synchronisation tool. All it can do is copy paste all the mentioned files from one location to another.
A more powerful tool is Rsync which not only has all functions of scp but adds more features to intelligently synchronise files across 2 hosts. For example, it can check and upload only the modified files, ignore existing files and so on.




Examples

Copy the file "foobar.txt" from a remote host to the local host

    $ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

    $ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar"

    $ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"

    $ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
    your_username@rh2.edu:/some/remote/directory/

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host

    $ scp foo.txt bar.txt your_username@remotehost.edu:~

Copy the file "foobar.txt" from the local host to a remote host using port 2264

$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory

Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all