1

I am currently using SFTP on my MacBook to perform file transfers with my brother's Linux (Ubuntu) system. Every time we need to share a file, I start the FTP server on my Mac by running the following command on Terminal:

/Users/Amit/Documents/Scriptlets/ftps.sh open

The content of this script is as follows:

#!/bin/sh
if [ $1 = 'open' ]; then
sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
echo SFTP opened
fi
if [ $1 = 'close' ]; then
sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
echo SFTP closed
fi
if [ $1 = 'check' ]; then
ftp localhost
echo check
fi

Once done, I give my local IP address, user name, and password to my brother who is already connected to my Mac over wifi and he uses that information to establish an FTP connection with me and share files.

The problem with this process is that I need to open Terminal every time I want to run this command and I need to enter my password there. Is there any way to automate this so that I just click an automator menu item on any of my Finder windows and feed it the password programmatically without manually opening up the Terminal program? Also, is there any way to ensure that my brother (or anyone I am providing my username and password) is able to access only a designated folder (preferably, Public folder) during the FTP session and nothing else?

Here's what I'd prefer to do every time I need to perform a file share with someone: I'd like to be able to just click on an (Automator) icon on my finder menubar to activate FTP on my system. Upon clicking, the Automator action should just open up FTP server on my laptop (the password being fed to it through the code itself) and throw a popup confirming the connection as active with the IP address that I need to relay to my brother so he could attempt to connect. Once the file transfer is done, I would like to just click on the same icon again and get a popup confirming that FTP has been closed. Is it too complicated a process?

1 Answer 1

1

Why use Automator when you can stay in bash?

I found a really cool little script called appify that will instantly turn other scripts into actual applications. You can try it a few times to observe its behavior. Since you already use bash, I am hoping that this answer as an alternative to exactly what you are asking for is acceptable. 

The idea is to split your script into 3 distinct scripts:


1: start ftp service on preferred network interface only
 #!/bin/bash
 #start ftp service
 #sudo="/usr/bin/sudo"
 #launchctl="/bin/launchctl"
 say="/usr/bin/say"
 networksetup="/usr/sbin/networksetup"
 tail="/usr/bin/tail"
 head="/usr/bin/head"
 cut="/usr/bin/cut"
 curl="/usr/bin/curl"
 currentInterface=$(networksetup -listnetworkserviceorder |tail +2 |head -n1 |cut -c5-12)
 getExternaladdress=$(curl ipecho.net/plain)
 SiriSays="say -v Samantha"
 #sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist 
 #your command will start ftp on all network interfaces
 if [ "$currentInterface" = "Airport" ]; 
      then
           networksetup -setpassiveftp Airport on
      else
           networksetup --setpassiveftp Ethernet on
 fi
 $SiriSays "ftp service has been initiated for the"
 echo $currentInterface |$SiriSays; $SiriSays "interface"
 $SiriSays "Your external IP address is"
 echo $getExternaladdress | $SiriSays
 exit

2: stop ftp service
 #!/bin/bash
 #stop ftp service
 #sudo="/usr/bin/sudo"
 #launchctl="/bin/launchctl"
 networksetup="/usr/sbin/networksetup"
 say="/usr/bin/say"
 tail="/usr/bin/tail"
 head="/usr/bin/head"
 cut="/usr/bin/cut"
 currentInterface=$(networksetup -listnetworkserviceorder |tail +2 |head -n1 |cut -c5-12)
 SiriSays="say -v Samantha"
 #sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
 #your command requires sudo
 if [ "$currentInterface" = "Airport" ]; 
      then
           networksetup -setpassiveftp Airport off
      else
           networksetup -setpassiveftp Ethernet off
 fi
 $SiriSays "ftp service has been terminated"
 exit

3: check ftp service status
 #!/bin/bash
 #check ftp service status
 networksetup="/usr/sbin/networksetup"
 say="/usr/bin/say"
 tail="/usr/bin/tail"
 head="/usr/bin/head"
 cut="/usr/bin/cut"
 currentInterface=$(networksetup -listnetworkserviceorder |tail +2 |head -n1 |cut -c5-12)
 SiriSays="say -v Samantha"
 if [ "$currentInterface" = "Airport" ]; 
      then
           networksetup -getpassiveftp Airport |$SiriSays
      else
           networksetup -getpassiveftp Ethernet |$SiriSays
 fi
 exit

Then apply the appify script to them

What you're left with is three little apps to put in your dock that, when launched, will start or stop the ftp service on your preferred network interface, or tell you what's up with ftp, respectively, and should not require any admin password. I only had time to test the first one, so if they don't work as I hope they do, then you can comment out or delete my logic and use your launchctl method.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .