ssh-xfer for Transferring Files

by Juliet Kemp

When it comes to file transfers, ssh-xfer brings together the best of the useful ssh and the ever-capable scp.

Juliet Kemp
ssh is a vital sysadmin tool, but it does have one major lack: the inability to transfer files within a session. scp is of course intended for this job, but it can be a nuisance to have to start up another connection for the transfer.

ssh-xfer uses the local SSH agent to transfer files using an existing connection. It can also do this over multiple connections: So if you've sshed into desktop A and then through that to server B, ssh-xfer will allow you to transfer a file directly from server B to your local machine. To make this work, you must patch your ssh-agent locally, and install thessh-xfer binary remotely. Note that it is limited in that you can transfer files only from the remote machine to the local machine, not vice versa.

Recent Tips
» Bash
» LDAP Master Server
» perltidy

Read All Tips of the Trade

To get this set up, you'll need the OpenSSH source code locally so you can apply the patch and build the ssh-xfer binary. Download the OpenSSH patch from the Web site and save it to the OpenSSH source directory. Then run

patch -p0 < patch-file-name 
Next, build the ssh-xfer binary, in the same directory, with:
./configure; make ssh-xfer

Finally, you must transfer the ssh-xfer binary to the remote server.

Now, run a bash shell via the new agent (ssh-agent-xfer bash), and open a connection to the server with agent forwarding enabled (ssh -A me@server.example.com). From this shell on the server, typessh-xfer testfile.txt, and testfile will be put in ~/Desktop on your local machine. You can change this default location by editing the XFER_DEST_DIR value in the ssh-xfer patch.

Note that enabling agent forwarding is a slight security risk, but the convenience may well be worth it!

This article was originally published on Monday Oct 20th 2008
Mobile Site | Full Site