2010
03.01

SFTP and FTP Linux Clients Suck.

Fortunately, there’s a program called sshfs which mounts an sftp connection as a drive using fuse. To install in Ubuntu,
sudo apt-get install sshfs.

Then, when you want to connect to an sftp server, add two aliases to your bashrc file like this:

#mounting alias
alias seanneilan.com='mkdir ~/ftp/seanneilan.com/; sshfs -o uid=1000 -o gid=1000 sneilan@seanneilan.com:/ -p 22 ~/ftp/seanneilan.com/; cd ~/ftp/seanneilan.com/home/sneilan'
#unmounting alias
alias useanneilan.com='cd ~; fusermount -u ~/ftp/seanneilan.com; rmdir ~/ftp/seanneilan.com'

To install

Choose a name for your connection. Mine is seanneilan.com. Copy/paste & replace all instances of seanneilan.com with the name of your connection. Replace sneilan@seanneilan.com:/ with your username, host & initial directory. Be sure to create a folder called ftp in your home directory.

How it works

  1. Make a folder for the files inside a folder called ftp in your home directory.
  2. Use sshfs to mount a connection inside that folder under your userid (no root required!) The uid=1000 & gid=1000 is your user id & group id on every linux system.
  3. Then, changes to that directory!
  4. The unmounting alias goes to your home directory, unmounts the ftp connection and removes the directory.

Issues

If you lose your connection, you’ll have to unmount, remount and reopen all your files since the file pointers will get messed up.

Ideas

I was thinking about implementing something with fschange. That way, I could make a program that makes a copy of whatever you’re about to edit and instead opens up the copy rather than the one on the sftp server. Then, when you save, fschange will notify some program to copy/paste your changes over to the sftp server. Should the sftp connection drop, the program will automatically reconnect. I might do this later.

Tips

It also helps if you use ssh keys.

1 comment so far

Add Your Comment
  1. This is actually really useful. I’ll give it a shot when I boot into Linux next.

Sean Neilan is Digg proof thanks to caching by WP Super Cache