Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TransportUtils:
- def __init__(self, host, port, login, password):
- self.host = host
- self.port = port
- self.login = login
- self.password = password
- def open_connection(self):
- self.client = paramiko.SSHClient()
- self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- self.client.connect(hostname=self.host, port=self.port, username=self.login, password=self.password)
- def get_transport(self):
- if self.client is None:
- open_connection(self)
- stdin, stdout, stderr = self.client.exec_command('ls -a') # ('apt list --installed')
- results = stdout.read()
- transport: paramiko.Transport = self.client.get_transport()
- if transport is None:
- raise UnknownTransport()
- return transport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement