From 978d22c7b7d0bc7b4a62d1dc5db9fa76cdd4d118 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Thu, 19 Jan 2012 19:38:31 -0600 Subject: Clean up upload error handling, fixes #11 --- logbot.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/logbot.py b/logbot.py index c001507..4b1cf3b 100644 --- a/logbot.py +++ b/logbot.py @@ -217,19 +217,18 @@ class Logbot(SingleServerIRCBot): remote_fname = "/".join(full_fname.split("/")[1:]) if DEBUG: print repr(remote_fname) - try: - self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb")) - except ftplib.error_perm, e: - code, error = str(e).split(" ", 1) - if code == "553": + # Upload! + try: self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb")) + # Folder doesn't exist, try creating it and storing again + except ftplib.error_perm, e: #code, error = str(e).split(" ", 1) + if str(e).split(" ", 1)[0] == "553": self.ftp.mkd(os.path.dirname(remote_fname)) 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()) - except ftplib.error, e: # Unsure of error, try reconnecting - self.set_ftp(connect_ftp()) + else: raise e + # Reconnect on timeout + except ftplib.error_temp, e: self.set_ftp(connect_ftp()) + # Unsure of error, try reconnecting + except ftplib.error, e: self.set_ftp(connect_ftp()) print "Finished uploading" -- cgit v1.2.3-70-g09d2