Indiana University
University Information Technology Services
  
What are archived documents?

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 dvader@indiana.edu 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:

#!/bin/sh ftp -n deathstar.org <<EOT | mailx -s "Your Listing" dvader@indiana.edu user anonymous dvader@indiana.edu cd /pub/docs/plans dir quit EOT

The first line indicates the file is a script. The second line invokes the ftp command and directs the output of the session to the mailx command. If mailx isn't on your system, try using mail or 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 dvader@indiana.edu with the subject Your Listing, as specified in the second line of the script.

To use the script, enter:

sh script_name

Replace 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 work, enter:

sh script_name &

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 named /pub/docs/plans existed on the remote host.

At Indiana University, to get support for personal or departmental Linux or Unix systems, see At IU, how do I get support for Linux or Unix?

Also see:

This is document afqg in domain all.
Last modified on August 22, 2008.
Please tell us, did you find the answer to your question?