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:])
|
remote_fname = "/".join(full_fname.split("/")[1:])
|
||||||
if DEBUG: print repr(remote_fname)
|
if DEBUG: print repr(remote_fname)
|
||||||
|
|
||||||
try:
|
# Upload!
|
||||||
self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb"))
|
try: self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb"))
|
||||||
except ftplib.error_perm, e:
|
# Folder doesn't exist, try creating it and storing again
|
||||||
code, error = str(e).split(" ", 1)
|
except ftplib.error_perm, e: #code, error = str(e).split(" ", 1)
|
||||||
if code == "553":
|
if str(e).split(" ", 1)[0] == "553":
|
||||||
self.ftp.mkd(os.path.dirname(remote_fname))
|
self.ftp.mkd(os.path.dirname(remote_fname))
|
||||||
self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb"))
|
self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb"))
|
||||||
else:
|
else: raise e
|
||||||
raise e
|
# Reconnect on timeout
|
||||||
except ftplib.error_temp, e: # Reconnect on timeout
|
except ftplib.error_temp, e: self.set_ftp(connect_ftp())
|
||||||
self.set_ftp(connect_ftp())
|
# Unsure of error, try reconnecting
|
||||||
except ftplib.error, e: # Unsure of error, try reconnecting
|
except ftplib.error, e: self.set_ftp(connect_ftp())
|
||||||
self.set_ftp(connect_ftp())
|
|
||||||
|
|
||||||
print "Finished uploading"
|
print "Finished uploading"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue