Guest User

Untitled

a guest
Feb 4th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class SSH_Connection:
  2. def __init__(self, LOCAL_IP, username, password):
  3. self.LOCAL_IP = LOCAL_IP
  4. self.username = username
  5. self.password = password
  6. self.client = paramiko.SSHClient()
  7. self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  8. self.client.connect(self.LOCAL_IP, username=self.username,password=self.password)
  9. self.scp = SCPClient(self.client.get_transport())
  10.  
  11. def std(self, message):
  12. self.message = message
  13. _in, out, err = self.client.exec_command(self.message)
  14. exitcode = out.channel.recv_exit_status()
  15. stdout = ''.join(out.read())
  16. stderr = ''.join(err.read())
  17. return stdout, stderr, exitcode
  18.  
  19. class _scp(SSH_Connection):
  20. def scp_put_file( self, localpath, remotepath):
  21. self.scp.put(localpath, remotepath)
  22. return
  23. def scp_get_file( self, localpath):
  24. self.scp.get(localpath)
  25.  
  26. unit = _scp('1.1.1.1', 'username', 'password')
Add Comment
Please, Sign In to add comment