Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

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, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document afqg in domain all.
Last modified on August 22, 2008.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.