Copying files between hosts: scp & sftp

scp and sftp are replacements for the old rcp and ftp utilities, respectively. They send secure information (such as your password) over an encrypted connection making them preferable to the old methods.

scp is useful for quickly sending a few files to and from machines. sftp is best for transferring large amounts of files interactively.

Using scp

To copy a file from another host, scp uses the format:

	scp source_file destination_file

If the source file or destination file are on a remote host, the format of either is:

	username@hostname:filename

For example, to copy a file called "file.txt" from your home directory on aidan to your current working directory do:

	scp username@aidan:~/file.txt .

The '~' character in the example above is a quick way of specifiying the home directory of the user ID you are connecting as.

Or send the file "updated.txt" to your home directory on aidan:

	scp updated.txt username@aidan:~/

Using sftp

sftp uses interactive commands, so to log onto a remote host you must first do:

	sftp username@hostname

Enter your password when prompted. Once logged in you can use standard FTP commands to list directories and send or receive files.

For example, to copy the file called "file.txt" from aidan and send a file called "updated.txt":

	sftp username@aidan
	username@aidan's password:
	sftp> ls
	.
	..
	Mail
	mail
	file.txt
	sftp> get file.txt
	Fetching /home/ucs/123/username/file.txt to file.txt
	sftp> put updated.txt
	Uploading updated.txt to /home/ucs/123/username/updated.txt
	sftp> quit

Other commands are available for dealing with large amounts of files and basic file management, see the sftp man page for more information.

Problems using scp & sftp

Most of the error messages from scp and sftp are self-explanatory, however on occasion you may see this message when connecting to a remote host:
	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
	Someone could be eavesdropping on you right now (man-in-the-middle attack)!
	It is also possible that the DSA host key has just been changed.

See the ssh help page on how to deal with this.