summaryrefslogtreecommitdiff
path: root/logbot.py
diff options
context:
space:
mode:
authorChris Oliver <excid3@gmail.com>2011-10-22 10:22:36 -0500
committerChris Oliver <excid3@gmail.com>2011-10-22 10:22:36 -0500
commitde141feeadde08a6d18453820ce23c7d2f6118c1 (patch)
tree4e35ffca6762a60980468b9ad9b1e0728f7bf200 /logbot.py
parent4713430ec8c62b2f24c481b9ae92fc77e09cff4c (diff)
downloadlogbot-de141feeadde08a6d18453820ce23c7d2f6118c1.tar.xz
Create directory on 553 error
Diffstat (limited to 'logbot.py')
-rw-r--r--logbot.py15
1 files 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)