Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1.  82 class Remote:
  2.  83     """Manage connections to remote servers"""
  3.  84     def __init__(self, hostname, username=None, password=None):
  4.  85         self.hostname = hostname
  5.  86         self.username = self.get_username(username)
  6.  87         self.password = self.get_password(password)
  7.  88         client = paramiko.SSHClient()
  8.  89         client.load_system_host_keys()
  9.  90         client.connect(self.hostname, 22, self.username, self.password)
  10.  91         self.sftp = client.open_sftp()
  11.  92
  12.  93     def get_username(self,username):
  13.  94         if not username:
  14.  95             default_username = getpass.getuser()
  15.  96             username = raw_input('Username [%s]: ' % default_username)
  16.  97         if len(username) == 0:
  17.  98             username = default_username
  18.  99         return username
  19. 100
  20. 101     def get_password(self,password):
  21. 102         if not password:
  22. 103                 password = getpass.getpass('Password for %s@%s: ' % (self.username, self.hostname))
  23. 104         return password
  24. 105
  25. 106     def sftp_stat(self,path):
  26. 107         self.sftp.stat(path)
  27. 108
  28. 109     def sftp_put(self,localpath, remotepath):
  29. 110         self.sftp.put(localpath, remotepath)
  30. 111
  31. 112     def sftp_list(self,remotepath=None):
  32. 113         self.sftp.listdir(remotepath)
  33. 114
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement