< Previous | Contents | Next >
scp And sftp
The OpenSSH package also includes two programs that can make use of an SSH-en- crypted tunnel to copy files across the network. The first, scp (secure copy) is used much like the familiar cp program to copy files. The most notable difference is that the source or destination pathnames may be preceded with the name of a remote host, fol- lowed by a colon character. For example, if we wanted to copy a document named doc- ument.txt from our home directory on the remote system, remote-sys, to the cur- rent working directory on our local system, we could do this:
[me@linuxbox ~]$ scp remote-sys:document.txt .
me@remote-sys's password:
[me@linuxbox ~]$ scp remote-sys:document.txt .
me@remote-sys's password:
document.txt
[me@linuxbox ~]$
100% 5581
5.5KB/s 00:00
document.txt
[me@linuxbox ~]$
As with ssh, you may apply a username to the beginning of the remote host’s name if the desired remote host account name does not match that of the local system:
[me@linuxbox ~]$ scp bob@remote-sys:document.txt .
[me@linuxbox ~]$ scp bob@remote-sys:document.txt .
The second SSH file-copying program is sftp which, as its name implies, is a secure re- placement for the ftp program. sftp works much like the original ftp program that we used earlier; however, instead of transmitting everything in cleartext, it uses an SSH encrypted tunnel. sftp has an important advantage over conventional ftp in that it does not require an FTP server to be running on the remote host. It only requires the SSH server. This means that any remote machine that can connect with the SSH client can also be used as a FTP-like server. Here is a sample session:
[me@linuxbox ~]$ sftp remote-sys
Connecting to remote-sys... me@remote-sys's password: sftp> ls
ubuntu-8.04-desktop-i386.iso sftp> lcd Desktop
sftp> get ubuntu-8.04-desktop-i386.iso
Fetching /home/me/ubuntu-8.04-desktop-i386.iso to ubuntu-8.04- desktop-i386.iso
[me@linuxbox ~]$ sftp remote-sys
Connecting to remote-sys... me@remote-sys's password: sftp> ls
ubuntu-8.04-desktop-i386.iso sftp> lcd Desktop
sftp> get ubuntu-8.04-desktop-i386.iso
Fetching /home/me/ubuntu-8.04-desktop-i386.iso to ubuntu-8.04- desktop-i386.iso
/home/me/ubuntu-8.04-desktop-i386.iso 100% 699MB
sftp> bye
7.4MB/s
01:35
/home/me/ubuntu-8.04-desktop-i386.iso 100% 699MB
sftp> bye
Tip: The SFTP protocol is supported by many of the graphical file managers found in Linux distributions. Using either Nautilus (GNOME) or Konqueror (KDE), we can enter a URI beginning with sftp:// into the location bar and operate on files stored on a remote system running an SSH server.
An SSH Client For Windows?
Let’s say you are sitting at a Windows machine but you need to log in to your Linux server and get some real work done; what do you do? Get an SSH client program for your Windows box, of course! There are a number of these. The most popular one is probably PuTTY by Simon Tatham and his team. The PuTTY pro- gram displays a terminal window and allow a Windows user to open an SSH (or telnet) session on a remote host. The program also provides analogs for the scp and sftp programs.
PuTTY is available at http://www.chiark.greenend.org.uk/~sgtatham/putty/