mar 262018
 

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.

Sorry, the comment form is closed at this time.