Using SCP

Command line and GUI clients / 2004-03-14

Not too long ago there was a time when one would update his or her site with their favorite FTP client and manage a server with telnet. Websites were made of static pages, perhaps some fancy SSI, and life was good. Today there is more shunning of clear text transferring, especially with the advent of open networks, wifi, and your local Big Brother. Now you do all you could with telnet and transfer files like FTP, with encrytion, all through one daemon - SSH (secure shell). This document will go over the basics of transferring files with SCP (Secure CoPy). Less widely available is SFTP (over SSH). This document does not cover SFTP, but know that there are pros and cons between SSH and SFTP.

Command line SCP

With ftp (command line), you're used to making the connection, logging in, and then transferring data. With SCP, you'll be doing all of the previous with a single command. As usual you should read the man pages on SCP and check its options. Let's take a look:

you@f00:/home/you$ scp
usage: scp [-pqrvBC46] [-F config] [-S program] [-P port]
[-c cipher] [-i identity] [-o option]
[[user@]host1:]file1 [...] [[user@]host2:]file2

Copy a file to the remote server

Lets say we want to transfer the file /home/f00/myfile.html to a webserver. We want to put it in /var/www/site/ on our server, remote.linux. The format is as follows:

you@f00:/home/you$ scp local_directory/file user@host:remote_directory/file

So we could use:

scp /home/f00/myfile.html f00@remote.linux:/var/www/site/myfile.html

Copy a file from the remote server

Here a file will be coppied from the server to your local box. This is simple, the command is just flipped:

you@f00:/home/you$ scp user@host:remote_directory/file local_directory/file

What it looks like

The first time you make SSH (and thus when you use SCP) connections to a host it will try to protect you from a man-in-the-middle attack. It will ask if the fingerprint matches what it's supposed to be. Other connections to the host, as long as the fingerprint matches, will not also ask you this question.

you@f00:/home/you$ scp myfile.html f00@remote.linux:/var/www/myfile.html
The authenticity of host 'remote.linux (192.168.1.50)' can't be established.
RSA key fingerprint is ma:f9:31:3c:1d:37:0a:ca:68:40:z1:bf:5c:c2:6c:13.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'remote.linux,192.168.1.50' (RSA) to the list of known hosts.
f00@remote.linux's password:
myfile.txt 100% |*****************************| 250 00:01

Multiple files: directory transfer

You will find use of being able to transfer a few files all together. To accomplish this you can copy a whole directory and its contents to or from a remote server. To accomplish this we need to point to directories and add the -r (recursive) flag to the scp command. This will transfer /remote_directory/example/ and its contents to /local_directory/example/:

you@f00:/home/you$ scp -r user@host:/remote_directory/example/ /local_directory/example

Pretty GUI clients

If you've never FTP'd from the command line and stuck only to the graphical clients you'll not fancy the above command line style transferring. Fortunately, there are some widely-used applications that will bring ease to the transfer. They are all self-explanatory in their use, and more information can be found at their sites.

Windows & Macintosh

The most popular client for Windows is WinSCP. You can learn about it and download from: http://winscp.sourceforge.net/eng/.

A popular tool for Apple systems is Fugu. It includes SFTP support: http://rsug.itd.umich.edu/software/fugu/.

Pour vous, Yaniv: rss_feed

On some mobile device? Try this.

vafrous.com: blog / articles / projects

©2008 vafrous.com, Mike Sklut / v0.4a / validate

\Va"frous\, a. [L. vafer.] Crafty; cunning; sly; as, vafrous tricks.