• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to catch ftp errors in shell script

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?>
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
reply
    Bookmark Topic Watch Topic
  • New Topic