From 925df20d1a95e52dc4a7a9f2b2c4fe5e378f4b38 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Tue, 13 Dec 2011 18:30:47 -0600 Subject: Reconnect FTP if we have a timeout. --- logbot.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/logbot.py b/logbot.py index 2460582..dd75edb 100644 --- a/logbot.py +++ b/logbot.py @@ -82,7 +82,7 @@ default_format = { } html_header = """ +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @@ -216,6 +216,9 @@ class Logbot(SingleServerIRCBot): self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb")) else: raise e + except ftplib.error_temp, e: # Reconnect on timeout + self.set_ftp(connect_ftp()) + print "Finished uploading" def append_log_msg(self, channel, msg): @@ -324,6 +327,12 @@ class Logbot(SingleServerIRCBot): self.write_event("topic", e) +def connect_ftp(): + print "Using FTP %s..." % (FTP_SERVER) + f = ftplib.FTP(FTP_SERVER, FTP_USER, FTP_PASS) + f.cwd(FTP_FOLDER) + return f + def main(): # Create the logs directory if not os.path.exists("logs"): @@ -335,14 +344,11 @@ def main(): try: # Connect to FTP if FTP_SERVER: - print "Using FTP %s..." % (FTP_SERVER) - f = ftplib.FTP(FTP_SERVER, FTP_USER, FTP_PASS) - f.cwd(FTP_FOLDER) - bot.set_ftp(f) + bot.set_ftp(connect_ftp()) bot.start() except KeyboardInterrupt: - if FTP_SERVER: f.quit() + if FTP_SERVER: bot.ftp.quit() bot.quit() -- cgit v1.2.3