The ability to mount FTP volumes locally gives administrators a real alternative to using NFS. It also gives users the ability to browse FTP servers while maintaining the advantages of operating with a local file system. You can use the ftpfs system on a LAN or on any remote FTP server to which users have access. This Daily Feature will describe how to install and configure ftpfs, either as a kernel module or as a kernel patch.
What you need To build ftpfs as a stand-alone kernel module, you'll need the following files:
The latest version of ftpfs, matching your kernel. The package is available from the Source Forge Web site. I used ftpfs-0.6.2-k2.4.tar.gz for this article.
The header files for the kernel must be installed. Almost all Linux distributions include the kernel headers with their default installation.
To build ftpfs as a kernel patch, you'll need the following files:
The ftpfs kernel patch
The latest version is ftpfs-0.3.0-k2.4.4.patch.gz
The ftpmount source code
Kernel source code
Building ftpfs as a kernel module To build ftpfs as a kernel module, first unpack the gzipped archive with this command: tar -zxvf ftpfs-0.6.2-k2.4.tar.gz
When the archive is unpacked, the directory ftpfs-0.6.2-k2.4 will be created. CD into the ftpfs-0.6.2-k2.4 directory and run the following command to build and install the ftpfs.o module and the ftpmount binaries: make install
To create an automount directory for ftpfs, run the following command: make install_automount
Building ftpfs as a kernel patch Before applying the kernel patch, you must install the kernel source code and header files. These files are typically located in /usr/src/linux. Next, run the following series of commands: cp ftpfs-0.3.0-k2.4.4.patch.gz /usr/src cd /usr/src gunzip ftpfs-0.3.0-k2.4.4.patch.gz cat ftpfs-0.3.0-k2.4.4.patch | patch -Np0
Once you’ve applied the patch to the kernel source, the next step is to compile the new kernel. Enter the /usr/src/linux directory and run any one of the following three commands: make config make menuconfig make xconfig
When you’ve selected the options for the new kernel, enable support for ftpfs under File Systems/Network FileSystems menu. When all of the options for the new kernel are selected, run the following series of commands to build your new kernel: make mrproper make dep make clean make bzImage make modules make modules_install
The ftpmount source code isn’t included with the kernel patch, so you have to compile it separately. To compile and build ftpmount, unpack its source code archive with this command: tar -zxvf ftpmount-1.1.tar.gz
The ftpfs module is also capable of running with automount / autofs. To mount FTP automatically in the /mnt/ftpfs directory, use the following command to build ftpfs: make install_automount
The ftpmount-1.1 directory will be created when the packaged is unpacked. Finally, enter the ftpmount-1.1 directory and run the following commands as root: make make install Mounting FTP volumes The biggest drawback to using ftpfs is the amount of bandwidth required. If you use a cable, ADSL, or similar Internet connection, you should have no problems. However, a dial-up connection probably won't provide the performance you're looking for. Using ftpmount The ftpmount command uses this format: ftpmount <user:password@ftp-server:port-number root-directory mount-point -own -uid -gid -fmask -dmask -active>
Below is an explanation of the ftpmount command:
User - The user name
Password - The user password
Ftp-server - The FTP server
Port - The port the FTP server is using
Root directory - The directory on the FTP server that will be mounted locally; this directory is normally specified without the trailing slash
Mount-point - The mount point for FTP volumes on the local system
Own - This option forces ownership of all remote files
UID - The User Identification
GID - The Group Identification
Fmask - The numerical mode applied to all mounted files
Dmask - The numerical mode applied to all mounted directories
Active - Enables support for active mode FTP transfers
Example This is an example of how you might use the ftpmount command. ftpmount jcmcintyre:abc123@update-server1:21 /linux-2.4 /mnt/ftpupdates -own -uid=500 -gid=500 -fmask=660 -dmask=770 In this example, the FTP server is actually located on the local network, and it’s used to provide software updates. The user password doesn't have to be passed as a command parameter since ftpmount will ask for it. Using the mount command If ftpmount isn't installed with ftpfs, you can use the mount command to mount remote FTP volumes. When you use the mount command, you must use the FTP server's IP address. For example, to mount the /pub/updates on the FTP server at 192.168.1.100 on a local system using the mount point /mnt/ftpfs, use the following command: mount -n -t ftpfs none /mnt/ftpfs -o ip=192.168.1.100 user=jim pass=123abc port=21 root=/pub/updates uid=500 gid=500 fmode=660 dmode=770
This command will mount the /pub/updates directory on the FTP server at /mnt/ftpfs on the local system. The local user would also assume ownership of all files in the local mounted volume.
Tips before you deploy ftpfs Here are some useful tips to remember about the mount command:
Forcing file ownership is convenient when the FTP server uses unconventional file access permissions.
Use the -n option with the mount command. This prevents the user password information form being written to /etc/mtab.
To unmount any mounted FTP volumes, use the umount command. For example, if an FTP volume is mounted at /mnt/ftpfs, use the command: umount /mnt/ftpfs
There are some points to remember about using ftpfs:
Limit the number of processes reading the mount point concurrently.
Concurrent access will work, but when only one process reads the mount point while the TCP connection is kept alive. Allowing other processes to read the mount will degrade performance.