1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacOS X LionのFTPサーバを起動したり停止たりするスクリプト

Posted at

Lionになってからシステム環境設定でFTPサーバのON・OFFができなくなったので。

ftp-server.sh

# !/bin/bash

show_brief() {
	echo "A FTP server manager."
}

show_usage() {
	name=$(basename $0)
	show_brief
	echo "usage:"
	echo "    $name start     : Start FTP server."
	echo "    $name stop      : Stop FTP server."
	echo "    $name status    : Show FTP server status."
}

is_ftp_server_running() {
	running=0
	sudo launchctl list com.apple.ftpd > /dev/null 2>&1 && running=1
	return $running
}

start_ftp_server() {
	is_ftp_server_running
	if [ $? -eq 1 ]
	then
		echo "FTP server is already started."
		exit 1
	fi

	sudo launchctl load -w /System/Library/LaunchDaemons/ftp.plist
	echo "Start FTP server [OK]"
}

stop_ftp_server() {
	is_ftp_server_running
	if [ $? -eq 0 ]
	then
		echo "FTP server is not started."
		exit 1
	fi

	sudo launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
	echo "Stop FTP server [OK]"
}

status_ftp_server() {
	is_ftp_server_running
	if [ $? -eq 1 ]
	then
		echo "FTP server is running."
	else
		echo "FTP server is unloaded."
	fi
}

unexpected_request() {
	show_usage
	exit 1
}

if [ $# -ne 1 ]
then
	unexpected_request
fi

case $1 in
	start)
		start_ftp_server
		;;
	stop)
		stop_ftp_server
		;;
	status)
		status_ftp_server
		;;
	*)
		unexpected_request
		;;
esac
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?