Breadcrumbs 
Learning >> Documentation >> Internet >> SCP
 
Recent News
We're No 1!
We've reached the top! (Of Google!)
[ more ]
Firefox 3 Download Day
Firefox 3 has been officially released and is looking to set a world record for the most downloaded piece of software in 24hrs.
[ more ]
SSL Renewed
SSL cert has been renewed by the admin team.
[ more ]
SCP
SCP

scp - secure copy (remote file copy program), copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh. Any file name may contain a host and user specification to indicate that the file is to be copied to/from that host. Copies between two remote hosts are permitted.

scp was only created as a hack to provide secure file transfer between computers until the sftp protocol was finialised and implemented. Now we prefer that sftp is used since it is supported by most servers including our own and is generally more efficient and versatile when transfering files via the internet. However its still a useful tool to know in the cases sftp is not available.

General options (and most useful)
-p : perserve permissions, this attempts to maintain the same permissions on the original file when coping to the new location.
-r : recursive copy entire directories.
-q : quiet mode, this basically just disables the progress meter.
-v : verbose mode, outputs debugging messages, useful for working out whats happening if the copy doesn't work.

While there's a few additional options they are only really for advanced use of this program which is rarely required. You can type man scp to get a complete list of options and their uses at the console. But where you need more advanced usage its better to use either sftp or rsync.


Lets take our first senario, your at home on the PC, have linux running and are connected to a linux server using ssh. There's a couple of files on your your machine under your default web folder that you want to copy up to your web folder on the server. You've got all the permissions sorted out so you don't want to have to redo them once the files are uploaded.

$ scp -pr ~/public_html/* username@server-address:~/public_html

Sub in your username for the username and the correct name for the server-address in the above example, which would be frink.nuigalway.ie or compsoc.nuigalway.ie . As you can see its basically scp [options] source-files destination-files. And for both the source and destination files you can specify the server/machine to connect to locate the files for coping.

For those of you who have access to the Computer Society servers and you don't have access to another linux machine to try this out the following command will demonstrate whats happening. Create a directory first called test under your home directory. Then use the command to copy the files. You may get some output asking if you are happy with the RSA fingerprint, this is just a identification id so that other hosts cannot trick you into thinking your accessing a differnet server.

$ mkdir ~/test
$ scp -pr ~/public_html/* username@localhost:~/test

If you need it you can also copy files from a remote server using the following format. The second line is the example for those using the compsoc server.

$ scp -pr username@server-address:~/public_html/* ~/public_html
$ scp -pr username@localhost:~/public_html/* ~/test

Note that entering your username followed by the @ symbol and finally the server-address is only required when the files followind the colon reside on a remote machine. Otherwise if you just enter the file(s) to copy its assumed that the location is the local machine.