Why does my ftp script quit after couple of hours?

Francesco Bochicchio bieffe62 at gmail.com
Fri Aug 14 18:27:30 CEST 2009


On 14 Ago, 18:03, kk <maymunbe... at gmail.com> wrote:
> Hi
> This way the first time I did something with ftp stuff. I think that
> generally it works but it stops working(quits or disappears) after
> couple of hours of running.
>
> This was a personal test-trial script for my own needs which was to
> get my dynamic ip and broadcast to a client(I have a client script on
> another computer). I sure could use something like DynDns for the same
> purpose with easier management but I just wanted to give it a try to
> see if i could even make it work .
>
> Basically this script parses my ip from DynDns ip check page and
> uploads it to the given ftp site. It works fine initially, it does
> upload, it updates the Ip every hour but the problem is that after
> couple of hours the Python console window disappears, I assume it
> crashes.  I know it does upload at least couple times(works for couple
> hours). it might be something to do with ftp connection. I will
> investigate that but I just wanted to see if I have any logic or some
> kind of contextual problem in the script.
>
> Here is the link to Pastie pagehttp://pastie.org/584152
>
> Thanks

Try catching the exception inside the main loop, to prevent your
program to exit in case of failure:

if __name__=='__main__':
  while True:
    try:
        writeExtFile(FILE_PATH,FILE_NAME)
        uploadFile
(FTP_NAME,FTP_USER_NAME,FTP_PASSWD,FTP_FOLDER,FILE_NAME)
        time.sleep(TIME_DELAY)
    except:
      err, det, tb = sys.exc_info()
      print "ERROR =>", err, det # gives you a description of the
occurred failure
      traceback.print_tb(tb) # this might be needed only for debug


Ciao
----
FB



More information about the Python-list mailing list