Here are three things you can do with the command-line FTP client:
- You can automatically grab a file using a one-line command. For instance, if a user named gwbush had a password yeehah and wanted to download iraq-invasion-plans.txt from ftp.thewhitehouse.com, he would type:
ftp ftp://gwbush:yeehah@ftp.thewhitehouse.com/iraq-invasion-plans.txt
The file would then be downloaded without a need for any further interaction. If he wanted to download a file outside his home directory, he could, but he'd need to type the first slash as its hex code — %2F — instead of the actual character. Check the manual page for further information.
- You can set up a file entitled .netrc in your home directory to automatically log you into FTP servers you commonly use. Using the information from the above example, if gwbush wanted to be able to automatically log onto ftp.whitehouse.com without having to type in his username and password each time, he would create a file called .netrc in his home directory containing this:
machine ftp.thewhitehouse.com login gwbush password yeehah
And bam!, auto-login!
- In that same .netrc file, you can set up macros to perform batches of FTP commands you do frequently. You can just make an alias for long directory names:
macdef my-mail cd /usr/local/maildirs/gwbush
Or you can automate downloading a file and deleting the remote copy (something that can't be done via the technique in hint number one):macdef spamgrab
These macros need to be prefaced with a dollar sign when typing them in — in other words, $my-mail or $spamgrab.
lcd /Users/gwbush/Desktop
cd /usr/local/maildirs/gwbush
ascii
get spam.txt
dele spam.txt
quit
The neat thing is that you can then echo this to the FTP command and, by doing so, automate nearly any batch process. For example, if you had auto-login already set up, you could run the above spamgrab batch from the Terminal by typing:echo $spamgrab | ftp ftp.thewhitehouse.com
- And don't forget that for convenience's sake, you can create an alias for any of the above commands. You could create an alias spamgrab for echo $spamgrab | ftp ftp.thewhitehouse.com, and then just type spamgrab in Terminal any time you wanted to grab that file off the remote server.
Or you could do it via an AppleScript application (through AppleScript's do shell script command) so you could get the file without loading Terminal. It all depends on what environment you spend the most time in, the GUI or the CLI. If you do it that way, though the above example needs an extra slash, so the AppleScript would be:do shell script "echo \$spamgrab | ftp ftp.thewhitehouse.com"

