Reconnect FTP if we have a timeout.

This commit is contained in:
Chris Oliver 2011-12-13 18:30:47 -06:00
parent 3af452f3b8
commit 925df20d1a

View file

@ -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()