Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ftplib
- import time
- import os
- class FTP(object):
- def __init__(self, host="", user="", password=""):
- self._ftp = ftplib.FTP(host, user, password)
- self._ftp.login(user, password)
- def cd(self, directory, auto_create=True):
- try:
- self._ftp.cwd(directory)
- except Exception as e:
- if auto_create:
- self.mkdir(directory, False)
- else:
- print e.args
- def put(self, file, bufsize=1024):
- self._ftp.storbinary("STOR "+file, open(file, "rb"), bufsize)
- def mkdir(self, directory, auto_rename=True, auto_cd=True):
- if auto_rename:
- directory = directory + "_" + time.ctime().replace(" ", "_").replace(":", "-")
- print directory
- self._ftp.mkd(directory)
- if auto_cd:
- self.cd(directory)
- else:
- self._ftp.mkd(directory)
- if auto_cd:
- self.cd(directory)
- def cwd(self):
- return self._ftp.pwd()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement