Guest User

Untitled

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