In Unix, how can I issue batches of non-interactive FTP commands?
In Unix, you can use the ftp command in
combination with a brief shell script to automate an FTP
session. For example, if your email address were
firstname.lastname@example.org and you wanted to retrieve a listing
of a directory named
/pub/docs/plans on a host named
deathstar.empire.org, you could use the following script:
The first line indicates the file is a script. The second line
ftp command and directs the output of the
session to the
mailx command. If
isn't on your system, try using
mhmail instead. The third line lists the login and
password for an anonymous FTP connection. The following
two lines contain the
ftp commands that the script will
execute on the remote host; you could substitute any valid
ftp commands of your own before the word
quit. Finally, once the commands have been executed, the
output will be mailed in a message to
with the subject
Your Listing, as specified in the second
line of the script.
To use the script, enter:sh script_name
script_name with the name of the file containing
the text of the script. If you would like to run the script in the
background so that you don't have to wait for it to finish to do other
You will receive an error message if, in your script, you refer to
directories or files that don't actually exist. In the example here,
we assumed that
dvader already knew that the directory
/pub/docs/plans existed on the remote host.
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on August 22, 2008.