Skip to main content
formatting fixed
Source Link
nohillside
  • 109.4k
  • 43
  • 232
  • 294

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:

#!/bin/bash                                                                                                                   

launchctl list | grep ftpd

if [ $? != 0 ];
  then
    IPADDR=$(ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1' | grep -v 127.0.0.1)
    launchctl load "/System/Library/LaunchDaemons/ftp.plist"
    osascript -e "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: \" & \"$USER\""
else
    launchctl unload -w "/System/Library/LaunchDaemons/ftp.plist"
    osascript -e 'tell application "Finder" to display alert "FTP session closed"'
fi

Run this a sudo. Explanation:

  • To check if job is running use launchctl list.
  • To get ip address quickly use my perl script (You may want to grep it differently in order to get rid of additional IP addresses.
  • The only problem now is that Finder app is not brought to front but this can be solved if needed.

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:

#!/bin/bash                                                                                                                   

launchctl list | grep ftpd

if [ $? != 0 ];
 then
IPADDR=$(ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1' | grep -v 127.0.0.1)
launchctl load "/System/Library/LaunchDaemons/ftp.plist"
osascript -e "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: \" & \"$USER\""
else
launchctl unload -w "/System/Library/LaunchDaemons/ftp.plist"
osascript -e 'tell application "Finder" to display alert "FTP session closed"'
fi

Run this a sudo. Explanation:

  • To check if job is running use launchctl list.
  • To get ip address quickly use my perl script (You may want to grep it differently in order to get rid of additional IP addresses.
  • The only problem now is that Finder app is not brought to front but this can be solved if needed.

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:

#!/bin/bash                                                                                                                   

launchctl list | grep ftpd

if [ $? != 0 ]; then
    IPADDR=$(ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1' | grep -v 127.0.0.1)
    launchctl load "/System/Library/LaunchDaemons/ftp.plist"
    osascript -e "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: \" & \"$USER\""
else
    launchctl unload -w "/System/Library/LaunchDaemons/ftp.plist"
    osascript -e 'tell application "Finder" to display alert "FTP session closed"'
fi

Run this a sudo. Explanation:

  • To check if job is running use launchctl list.
  • To get ip address quickly use my perl script (You may want to grep it differently in order to get rid of additional IP addresses.
  • The only problem now is that Finder app is not brought to front but this can be solved if needed.
Source Link
Mateusz Szlosek
  • 24.9k
  • 3
  • 69
  • 74

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:

#!/bin/bash                                                                                                                   

launchctl list | grep ftpd

if [ $? != 0 ];
then
IPADDR=$(ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1' | grep -v 127.0.0.1)
launchctl load "/System/Library/LaunchDaemons/ftp.plist"
osascript -e "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: \" & \"$USER\""
else
launchctl unload -w "/System/Library/LaunchDaemons/ftp.plist"
osascript -e 'tell application "Finder" to display alert "FTP session closed"'
fi

Run this a sudo. Explanation:

  • To check if job is running use launchctl list.
  • To get ip address quickly use my perl script (You may want to grep it differently in order to get rid of additional IP addresses.
  • The only problem now is that Finder app is not brought to front but this can be solved if needed.