Site icon AppTeam

Mount remote FTP server as folder on Linux and auto startup it

Sometimes we need to mount the FTP server as a folder on Linux and automatically mount it on reboot. We used this system on a client who needed to back up to an external server. This example is for CentOS 7.

# Installing the CurlFtpFS package (need EPEL repo):
yum install curlftpfs

A few CurlFtpFS command.

# $ftphost = The FTP host
# $mount = Mounted to folder
# $user = FTP username
# $pass = FTP password

# Mount the CurlFtpFS

curlftpfs $ftphost $mount -o user=$user:$pass,allow_other

# Unmount the CurlFtpFS

fusermount -u $mount

Auto mount CurlFtpFS

Creating the startup script:

vi /etc/init.d/mountftp

Copy and paste this. Change the FTP credentials and mounted to folder.

# Run-level Startup script for curlftpfs
# chkconfig: 345 91 19
# description: Startup/Shutdown the curlftpfs

# FTP user, password, and host (you can specify the port also eg.

# Mounted to folder

# Create the mounted to dir if doesn’t exist
if [ ! -d $mPath ]; then
mkdir -p $mPath

case “$1” in
curlftpfs $ftpHost $mPath -o user=$ftpUser:$ftpPass,allow_other
fusermount -u $mPath
$0 stop
$0 start
echo “Usage: $0 start|stop|restart|reload”
exit 1
exit 0

Make the startup script persistent across reboot.

# chkconfig mountftp on

Available command.

# Start
service mountftp start

# Restart and reload
service mountftp restart
service mountftp reload

# Stop
service mountftp stop

Exit mobile version