Skip to content

Instantly share code, notes, and snippets.

@justinhartman
Last active February 26, 2018 20:03
Show Gist options
  • Save justinhartman/7553191 to your computer and use it in GitHub Desktop.
Save justinhartman/7553191 to your computer and use it in GitHub Desktop.
Debian Remote FTP Server Mount Script

Debian Remote FTP Server Mount Script

The following is a Debian based Remote FTP Server Mount script that will connect to an FTP server at boot time and mount the fileshare to the filesystem at /mnt/ftpserver. This script depends on curlftpfs and umount and you may need to install them if they're not already installed. You can change the MOUNT path to any path on your server and please don't forget to replace the ftp details in the OPTIONS string.

Shell Script

Here's the script to use. Save it to disk, naming it something like ftp-mount.sh.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          ftpserver
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start ftpserver daemon at boot time
# Description:       Enable ftpserver service provided by daemon.
### END INIT INFO

# Author: Justin Hartman <justin@hartman.me>
# URL: http://justinhartman.co.za
# From Debian skeleton

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/curlftpfs
OPTIONS="-o allow_other ftp://myusername:mypassword@ftp.mydomain.com"
MOUNT=/mnt/ftpserver
UMOUNT=/bin/umount
NAME=ftpserver
DESC="Remote FTP Server Mount"

PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

case "$1" in
  start)
	echo -n "Mounting the $DESC: $NAME"
	$DAEMON $OPTIONS $MOUNT
	echo "Server has been mounted at $MOUNT"
	;;
  stop)
	echo -n "Stopping $DESC: $NAME"
	$UMOUNT $MOUNT
	echo "Server has been unmounted"
	;;
  restart|force-reload)
	echo -n "Re-mounting the $DESC: $NAME"
	$UMOUNT $MOUNT
	sleep 2
	$DAEMON $OPTIONS $MOUNT
	echo "The server has been re-mounted at $MOUNT"
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment