Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 82 class Remote:
- 83 """Manage connections to remote servers"""
- 84 def __init__(self, hostname, username=None, password=None):
- 85 self.hostname = hostname
- 86 self.username = self.get_username(username)
- 87 self.password = self.get_password(password)
- 88 client = paramiko.SSHClient()
- 89 client.load_system_host_keys()
- 90 client.connect(self.hostname, 22, self.username, self.password)
- 91 self.sftp = client.open_sftp()
- 92
- 93 def get_username(self,username):
- 94 if not username:
- 95 default_username = getpass.getuser()
- 96 username = raw_input('Username [%s]: ' % default_username)
- 97 if len(username) == 0:
- 98 username = default_username
- 99 return username
- 100
- 101 def get_password(self,password):
- 102 if not password:
- 103 password = getpass.getpass('Password for %s@%s: ' % (self.username, self.hostname))
- 104 return password
- 105
- 106 def sftp_stat(self,path):
- 107 self.sftp.stat(path)
- 108
- 109 def sftp_put(self,localpath, remotepath):
- 110 self.sftp.put(localpath, remotepath)
- 111
- 112 def sftp_list(self,remotepath=None):
- 113 self.sftp.listdir(remotepath)
- 114
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement