Created
February 9, 2015 20:34
-
-
Save tjluoma/aa49f0a5499654c22a3c to your computer and use it in GitHub Desktop.
Easily turn FTPD on or off, or just see the status of it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# | |
# Author: Timothy J. Luoma | |
# Email: luomat at gmail dot com | |
# Date: 2014-05-08 | |
# | |
# Purpose: enable / disable ftpd on OS X Lion (or later) | |
# | |
# URL: https://github.com/tjluoma/ftpd/ | |
# | |
# Thanks to: http://www.landofdaniel.com/blog/2011/07/22/starting-ftp-server-in-os-x-lion/ | |
# (although I don't know why he suggests `-s` as a separate line) | |
## 2014-05-08: Instead of calling the entire script via `sudo` just call the lines which actually require it | |
# customize this if you wish, or just remove it… you won't normally need it | |
PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
# same as `basename $0` | |
NAME="$0:t" | |
# this is where OS X keeps the plist | |
PLIST='/System/Library/LaunchDaemons/ftp.plist' | |
if [[ ! -e "$PLIST" ]] | |
then | |
# this should never happen, but just in case... | |
echo "$NAME: cannot find $PLIST" | |
exit 2 | |
fi | |
# function to check status of FTPD | |
function status { | |
STATUS=`sudo /bin/launchctl list | fgrep -i com.apple.ftpd` | |
if [ "$STATUS" = "" ] | |
then | |
STATUS=off | |
else | |
STATUS=on | |
fi | |
echo "$STATUS" | |
} | |
# function to turn ftpd-on | |
function ftp-on { | |
CURRENT=`status` | |
if [ "$CURRENT" = "on" ] | |
then | |
echo "$NAME: ftp is already ON" | |
exit 0 | |
else | |
# load the plist | |
sudo /bin/launchctl load -w "${PLIST}" && \ | |
echo "$NAME: ftpd is now loaded [enabled/ready]" && \ | |
exit 0 | |
fi | |
} | |
# function to turn ftpd-off | |
function ftp-off { | |
CURRENT=`status` | |
if [ "$CURRENT" = "off" ] | |
then | |
echo "$NAME: ftp is already OFF" | |
exit 0 | |
else | |
# unload the plist | |
sudo /bin/launchctl unload -w "${PLIST}" && \ | |
echo "$NAME: ftpd is now unloaded [disabled]" \ | |
&& exit 0 | |
fi | |
} | |
######################################################################################### | |
# | |
# | |
# if the argument has the word "on" or "enable" or "load" then turn it on | |
# if the argument has the word "off" or "disable" or "unload" then turn it off | |
# | |
# otherwise, just show the current status | |
case "$1" in | |
*on*|*ON*|*enable*|*ENABLE*|load|LOAD) | |
ftp-on | |
exit | |
;; | |
*off*|*OF*|*disable*|*DISABLE*|unload|UNLOAD) | |
ftp-off | |
exit | |
;; | |
esac | |
# if no arguments are given, just show the current status | |
status | |
######################################################################################### | |
exit 0 | |
#EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment