[Tutor] fortify this code...

Deirdre Saoirse deirdre@deirdre.net
Thu, 21 Oct 1999 16:21:50 -0700 (PDT)


On Thu, 21 Oct 1999, Tim Wilson wrote:

> # Do the FTP get
> ftp = FTP(noaa_url)
> ftp.login()
> ftp.cwd(metar_dir)
> ftp.retrbinary('RETR ' + station_id + '.TXT', data.write)
> ftp.quit

You need to put a try: before the ftp = line to help bulletproof it.

> It crashes and burns, however, if the NOAA ftp server is busy or otherwise
> unavailable. How can I make this script retry the connection a few times
> and failing that, exit gracefully. I also notice that I'll have to change
> it so that the old file isn't overwritten until the new data is available.
> Thanks for any advice that any of you might have.

You probably want a while loop around the ftp part that will retry the
connection a few times. You may also wish to cache it locally. :)

If it's available via http AND you have a caching proxy like squid, your
reliability will improve.

-- 
_Deirdre   *   http://www.linuxcabal.net   *   http://www.deirdre.net
"Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator
"That's because the Martians keep shooting things down." -- Harlan Rosenthal
<Harlan.Rosenthal@Dialogic.com>, retorting in Risks Digest 20.60