Mounting ftp host to local directory on top of FUSE
November 17th, 2007 mysurface Posted in Admin, curlftpfs, mount, sudo, umount | Hits: 33134 |
I have wrote a post regarding on how to access ftp host using curl. And this time, let us look at how to mount the ftp host to a local directory on top of FUSE.
FUSE (Filesystem in userland) is a userland build on top of virtual filesystem, it allows you to implement functional filesystem in userspace application. Robson Braga Araujo wrote an app based on fuse and curl that allows you to mount a ftp host to a local directory, curlftpfs.
What is the benefit of mounting ftp host to a local directory?
The most obvious benefit is easing file management in ftp host. After mounting ftp host to a local dir, you can simply copy, move and delete files using command such as cp, mv, rm. You can easily transfer files from your localhost to ftp host and vice versa.
To mount ftp host to your local directory, first you need to create a local directory, I created a folder ‘myftp’ and mounting it like this
sudo curlftpfs -o allow_other ftp://myusername:mypassword@ftp.mydomain.com myftp
As simple as that, you are now able to access your ftp host locally.
How to unmount it?
Unmount works as usual.
sudo umount myftp
The command line is lengthy for me, can I auto mount my ftp host by putting it to /etc/fstab ?
Yes, curlftpfs support that.
Inject this line to /etc/fstab
curlftpfs#myusername:mypassword@ftp.mydomain.com /mnt/myftp fuse allow_other,rw,user,noauto 0 0
With noauto option, this mount point will not be auto mount when your system restart, you need mount it manually. But this time, you do not need to type the long command line, you now can do this:
sudo mount /mnt/myftp
You may observed that I use allow_other in the option, so that I can access /mnt/myftp without need to change myself to root.
Security Issues
Try to run the command line below:
ps aux | grep curlftpfs
OMG! my username and password of my ftp host is visible. I am very sensitive about this, I don’t want it to be so visible, what should I do?
You can create .netrc under root directory and modified the mount line in /etc/fstab.
1. Create /root/.netrc and paste these lines in it.
machine ftp.byexamples.com
login myusername
password mypassword
2. Modified the user mode of the file
sudo chmod o-rw /root/.netrc
3. Modified /etc/fstab
curlftpfs#ftp.mydomain.com /mnt/myftp fuse allow_other,rw,user,noauto 0 0
Although your /root/.netrc is in plain text, but you will need to gain root privilege in order to access the file.
Live Chat!









November 18th, 2007 at 1:25 pm
Nice!
And quite useful! Half the day at work I have gFTP open all day. I will be mounting many of my more commonly used FTP sites this way.
November 19th, 2007 at 1:30 pm
[...] From Linux by Examples [...]
November 24th, 2007 at 12:54 am
I can’t edit files in mounted directories although I’ve set 777 to all dirs and subdirs. So it’s tottaly useless.
November 24th, 2007 at 1:04 am
Weird, I can edit things just fine via nano when they are stored on the FTP server. I can’t seem to edit with gedit in Ubuntu (Gutsy) but I have no problem with I use nano.
Since I usually need to edit config files via the mounted FTP server it works fine for me since for those tasks, I prefer nano. Same goes for editing HTML or PHP files.
November 24th, 2007 at 2:32 am
hiryuu, techfun: You guys are right, I having problem rm or vi the files in my ftp site, but cp, mv is working fine. While saving edited page from vi, it cause disconnection, probably it is a bug for curlftpfs? or it maybe that my ftp site have tight security which do not allow direct edit?
November 30th, 2007 at 11:34 pm
I’ve a similar problem - editing files with gedit causes a segmentation fault in curlftpfs which then renders the connection unusable.
I suspect it’s an error in the curl library. I’ve seen reference to it elsewhere. Unfortunately, Ubuntu Gutsy doesn’t seem to have the latest version of the curl, so it’s difficult to tell whether the problem has now been fixed.
July 29th, 2008 at 1:01 pm
One thing to note, is that sudo is not needed for much of this.
Fuse can be run as a user, as long as you’re mounting a drive somewhere you have write permissions, such as
~/remote-ftp
or other.
curlftpfs ftp://myusername:mypassword@ftp.mydomain.com ~/remote-ftp
works just fine on my system without having to muck about as root.