Clean up upload error handling, fixes #11
This commit is contained in:
parent
8e0362d4bf
commit
978d22c7b7
1 changed files with 10 additions and 11 deletions
21
logbot.py
21
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"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue