Secure remote copy with scp

For copying files between different hosts from console, scp is your first choice, since it uses commonly used ssh1 protocol, that will be available on (almost) any machine.

The structure is like this:

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [

[user@]host1:]file1 … [ [user@]host2:]file2

Short example: if you want to copy some file from current host to a remote host your command will be like this:

scp -p /home/user/yourfile.tgz   user:pass@remotehost:/home/someuser/your_directory/

where -p = preserve file properties (modification time, modes, etc.)

if want to copy all files and subdirectories in a folder for example you will need to add -r , which stands for recursive copy

scp -rp /home/user/somedirecory/*   user:pass@remotehost:/home/someuser/your_directory/

I will not describe all the parameters here, for a complete description you can read the man page here: http://linux.die.net/man/1/scp 

Usually ssh is listening on port 22, and if your hosts ( source or destination) are listening on the standard port, you do not need to specify it, but if any of the hosts is configured to listen on some other port ( usually for increased security reasons ), then you must specify it with -P ( notice that is capital P, since p is reserved for “preserve properties” from rcp command )

scp 

scp -P 2222 -r user:pass@remotehost:portnumber/home/someuser/source_directory/*  /home/user/

 

, or as an alternative you may specify the port at the end of the url, separeted by : , like you would do on ftp login

scp -p /home/user/yourfile.tgz   user:pass@remotehost:portnumber/home/someuser/your_directory/

 

Hope this is useful for those searching for a quick remote copy solution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: