I just wrote an Automator app using AppleScript (along with a couple of bash lines) to start FTP with a single click. However it runs more than a tad slow. Here's the code:
set ftpstatus to "off"
try
do shell script "echo \"QUIT\" | telnet 127.0.0.1" & " ftp 2>&1 | grep \"Escape character is\" > /dev/null"
set ftpstatus to "on"
on error
set ftpstatus to "off"
end try
if (ftpstatus = "off") then
set ipaddr to IPv4 address of (get system info)
set sun to short user name of (get system info)
do shell script "sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist" with administrator privileges
tell application "Finder" to display alert "FTP Launched and ready for file-transfer" & character id 8233 & character id 8233 & character id 8233 & "Address: ftp://" & ipaddr & ":21" & character id 8233 & "User Name: " & sun
else
do shell script "sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist" with administrator privileges
tell application "Finder" to display alert "FTP session closed"
end if
Here's what the code does:
- Check if FTP server is running
- If yes, turn it off and throw a message box saying "FTP session closed"
- If no, turn it on and throw a message box saying "FTP session open" along with my IP address and username
This script works like charm but since it's too slow, I am wondering if there's any way to convert it to a bash shell script. That should speed up things a lot. Any suggestions?
Best Answer
I'm not sure I understand correctly - if in the third line of Your script You're checking whether
ftp
service is running You can use following script:Run this a
sudo
. Explanation:launchctl list
.grep
it differently in order to get rid of additional IP addresses.