Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ftplib
- import json
- import cryptography.fernet
- # import getpass
- class FTPUtils:
- def __init__(self, hostname, user, password):
- self.host = hostname
- self.user = user
- self.password = password
- self.ftp = ftplib.FTP()
- self.ftp.connect(self.host)
- self.ftp.login(self.user, self.password)
- def upload(self, upload_item):
- cmd = 'STOR {}'.format(upload_item)
- self.ftp.storbinary(cmd, open(upload_item, 'rb'))
- print("done uploading: {}".format(upload_item))
- def ls(self):
- self.ftp.retrlines('LIST')
- def __del__(self):
- self.ftp.close()
- config = json.load(open('ftpauth.json'))
- host = config['hostname']
- user = config['username']
- key = config['key'].encode('ascii') # unicode into byte string
- token = config['password_token'].encode('ascii')
- f = cryptography.fernet.Fernet(key)
- password = f.decrypt(token).decode('ascii') # byte into unicode
- f = FTPUtils(host, user, password)
- f.upload('passwd.txt')
- f.ls()
Add Comment
Please, Sign In to add comment