aspose file tools*
The moose likes Linux / UNIX and the fly likes How to catch ftp errors in shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to catch ftp errors in shell script" Watch "How to catch ftp errors in shell script" New topic
Author

How to catch ftp errors in shell script

manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
Following is the extract of my shell script (bash) -

My problem is if for some reason, ftp could not logged in successfully, still my script goes ahead and executed the stuff. How can I stop my execution if there is any type of exception [saying login error, file not found, etc.]. Can anyone help me out please?>


love your job and not your company;
...because you never know when your company will stop loving you!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11477
    
  94

The Expect scripting language was created for just such a purpose. The Wikipedia article on Expect even has an example (under "Below is an example that automates sftp") that handles timeouts before login. There is an example script at Sun that shows how to use FTP to log into different types of machines - e.g. if the prompts are different. (TCL / TK were a Sun product at the same time Java first came out, and Expect is built on TCL)

You can decide for yourself what to do if you do not login - do you simply stop, do you retry 'x' times, do you try a different box ...

TCL / TK / Expect are available every version of Linux (and most Unix systems I have worked with). Many Linux systems come with it pre-installed (especially if you have dial-up networking installed - many of the dial-up scripts are Expect scripts).


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to catch ftp errors in shell script