Mounting ftp host to local directory on top of FUSE

November 17th, 2007 mysurface Posted in Admin, curlftpfs, mount, sudo, umount | Hits: 100983 | 18 Comments »

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.

18 Responses to “Mounting ftp host to local directory on top of FUSE”

  1. 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.

  2. [...] From Linux by Examples [...]

  3. I can’t edit files in mounted directories although I’ve set 777 to all dirs and subdirs. So it’s tottaly useless.

  4. 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.

  5. 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?

  6. 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.

  7. 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.

  8. Thanks, this really helped

  9. I have similar problems when i save files using gedit or bluefish, it cause the aplication doesn’t respond. I don’t know what’s going on. Sorry for my english i am from Argentina.

  10. I had problems writing/saving remote files through ex emacs but by passing the direct_io in the -o switch it works.

    “curlftpfs -o allow_other,direct_io ftp://…

  11. The option _netdev should be added to the /etc/fstab lines.
    Mount will then wait until network is running before mounting.

  12. When I am logged as root and type:
    mount /mountpoint
    it gives me an:
    Operation no permitted error.

    I have set it up like you said above with the .netrc file and fstab file.

    What do I do?

  13. Sorry.
    The error message above is:
    mount: curlftpfs#ftp.domain.com : Operation not supported by device.

  14. Excellent instructions, thank you – very useful!

  15. CRM is a global service provider in the areas of contact center, BPO and technology services. The company is strategically located in Gurgaon, an integral and key part of National Capital Region of Delhi, close to both human and technological resources and boasts of cutting edge facility capable of competing with the best of Business Process Off-shoring organizations.

  16. [...] – Mounting ftp host to local directory on top of FUSE Share this:TwitterFacebookLike this:LikeBe the first to like [...]

  17. I like your webpage. Incredible expertise about field sobriety tests are they
    designed for failure. Thanks a lot for sharing.

  18. Fantastic info! Saved a ton of work rsyncing via this method instead of using ftp.

Leave a Reply