Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- from paramiko import SSHClient, AutoAddPolicy
- from scp import SCPClient
- class SSH_Connection:
- def __init__(self, LOCAL_IP, username, password):
- self.LOCAL_IP = LOCAL_IP
- self.username = username
- self.password = password
- self.client = paramiko.SSHClient()
- self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- self.client.connect(self.LOCAL_IP, username=self.username,password=self.password)
- self.scp = SCPClient(self.client.get_transport())
- def std(self, message):
- self.message = message
- _in, out, err = self.client.exec_command(self.message)
- exitcode = out.channel.recv_exit_status()
- stdout = ''.join(out.read())
- stderr = ''.join(err.read())
- return stdout, stderr, exitcode
- class _scp(SSH_Connection):
- def scp_put_file( self, localpath, remotepath):
- self.scp.put(localpath, remotepath)
- return
- def scp_get_file( self, localpath):
- self.scp.get(localpath)
- unit = _scp('1.1.1.1', 'username', 'password')
Add Comment
Please, Sign In to add comment