Create directory on 553 error
This commit is contained in:
parent
4713430ec8
commit
de141feead
1 changed files with 12 additions and 3 deletions
15
logbot.py
15
logbot.py
|
@ -33,7 +33,7 @@ __license__ = "GPL2"
|
||||||
|
|
||||||
import cgi
|
import cgi
|
||||||
import os
|
import os
|
||||||
from ftplib import FTP
|
import ftplib
|
||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -206,7 +206,16 @@ class Logbot(SingleServerIRCBot):
|
||||||
full_fname = os.path.join(root, fname)
|
full_fname = os.path.join(root, fname)
|
||||||
|
|
||||||
remote_fname = "/".join(full_fname.split("/")[1:])
|
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"
|
print "Finished uploading"
|
||||||
|
|
||||||
def append_log_msg(self, channel, msg):
|
def append_log_msg(self, channel, msg):
|
||||||
|
@ -327,7 +336,7 @@ def main():
|
||||||
# Connect to FTP
|
# Connect to FTP
|
||||||
if FTP_SERVER:
|
if FTP_SERVER:
|
||||||
print "Using FTP %s..." % (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)
|
f.cwd(FTP_FOLDER)
|
||||||
bot.set_ftp(f)
|
bot.set_ftp(f)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue