daily pastebin goal
7%
SHARE
TWEET

FTP.py

a guest Aug 13th, 2016 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ftplib
  2. import time
  3. import os
  4.  
  5. class FTP(object):
  6.     def __init__(self, host="", user="", password=""):
  7.         self._ftp = ftplib.FTP(host, user, password)
  8.         self._ftp.login(user, password)
  9.  
  10.     def cd(self, directory, auto_create=True):
  11.         try:
  12.             self._ftp.cwd(directory)
  13.         except Exception as e:
  14.             if auto_create:
  15.                 self.mkdir(directory, False)
  16.             else:
  17.                 print e.args
  18.  
  19.  
  20.     def put(self, file, bufsize=1024):
  21.         self._ftp.storbinary("STOR "+file, open(file, "rb"), bufsize)
  22.  
  23.     def mkdir(self, directory, auto_rename=True, auto_cd=True):
  24.         if auto_rename:
  25.             directory = directory + "_" + time.ctime().replace(" ", "_").replace(":", "-")
  26.             print directory
  27.             self._ftp.mkd(directory)
  28.             if auto_cd:
  29.                 self.cd(directory)
  30.         else:
  31.             self._ftp.mkd(directory)
  32.             if auto_cd:
  33.                 self.cd(directory)
  34.  
  35.     def cwd(self):
  36.         return self._ftp.pwd()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top