Guest User

Untitled

a guest
Jul 26th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import ftplib
  2. import json
  3. import cryptography.fernet
  4.  
  5.  
  6. # import getpass
  7.  
  8.  
  9. class FTPUtils:
  10. def __init__(self, hostname, user, password):
  11. self.host = hostname
  12. self.user = user
  13. self.password = password
  14. self.ftp = ftplib.FTP()
  15. self.ftp.connect(self.host)
  16. self.ftp.login(self.user, self.password)
  17.  
  18. def upload(self, upload_item):
  19. cmd = 'STOR {}'.format(upload_item)
  20. self.ftp.storbinary(cmd, open(upload_item, 'rb'))
  21. print("done uploading: {}".format(upload_item))
  22.  
  23. def ls(self):
  24. self.ftp.retrlines('LIST')
  25.  
  26. def __del__(self):
  27. self.ftp.close()
  28.  
  29.  
  30. config = json.load(open('ftpauth.json'))
  31. host = config['hostname']
  32. user = config['username']
  33. key = config['key'].encode('ascii') # unicode into byte string
  34. token = config['password_token'].encode('ascii')
  35. f = cryptography.fernet.Fernet(key)
  36. password = f.decrypt(token).decode('ascii') # byte into unicode
  37.  
  38. f = FTPUtils(host, user, password)
  39. f.upload('passwd.txt')
  40. f.ls()
Add Comment
Please, Sign In to add comment