7. OS X
updated: Oct 27, 2001
The following article was kindly submitted by William Kitchen.
An often overlooked feature of the Windows command line ftp program is that it can be scripted. The script is simply a text file containing exactly what you would have typed if using it interactively.
For example, if you create a text file called "updatewebsite" containing something similar to this:
you can then update your web site by typing this at the command line:
While browsing the web I stumbled upon an excellent web page about batch programming that describes a clever way to embed an ftp script in a batch file that passes itself to the ftp program as the script.
If you're familiar with batch files, you probably already know that a batch file can reference command line parameters using %1 for the first parameter, %2 for the second, etc. But less widely known is that %0 is also valid, and represents the item before the first parameter on the command line, which is, of course, the command itself.
If you create a file called getmydata.bat containing this:
you could then retrieve "mydata.dat" from the remote system just by typing "getmydata" at a command line. If it's something you do a lot, you could make it even easier by placing a shortcut on your desktop or quicklaunch toolbar.
The ftp script is effectively hidden from the batch interpreter because the second line causes the batch interpreter to skip over it. You can't hide the first two batch commands from the ftp program, but the script works anyway because the ftp program simply generates an error message and skips to the next line whenever it encounters something it doesn't understand. Any batch commands added after the ":done" label will not be seen by the ftp program because it exits when it gets to the "bye" at the end of the script.