From de141feeadde08a6d18453820ce23c7d2f6118c1 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Sat, 22 Oct 2011 10:22:36 -0500 Subject: Create directory on 553 error --- logbot.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/logbot.py b/logbot.py index 2c0fbcc..2f6151a 100644 --- a/logbot.py +++ b/logbot.py @@ -33,7 +33,7 @@ __license__ = "GPL2" import cgi import os -from ftplib import FTP +import ftplib from time import strftime try: @@ -206,7 +206,16 @@ class Logbot(SingleServerIRCBot): full_fname = os.path.join(root, fname) remote_fname = "/".join(full_fname.split("/")[1:]) - self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb")) + print 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": + self.ftp.mkd(os.path.dirname(remote_fname)) + self.ftp.storbinary("STOR %s" % remote_fname, open(full_fname, "rb")) + else: + raise e print "Finished uploading" def append_log_msg(self, channel, msg): @@ -327,7 +336,7 @@ def main(): # Connect to FTP if FTP_SERVER: print "Using FTP %s..." % (FTP_SERVER) - f = FTP(FTP_SERVER, FTP_USER, FTP_PASS) + f = ftplib.FTP(FTP_SERVER, FTP_USER, FTP_PASS) f.cwd(FTP_FOLDER) bot.set_ftp(f) -- cgit v1.2.3