Skip to content

Instantly share code, notes, and snippets.

@perillo
Forked from webs86/py_ssh.py
Last active August 22, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save perillo/8c492a6a021e71034b1c33fb085a6679 to your computer and use it in GitHub Desktop.
Save perillo/8c492a6a021e71034b1c33fb085a6679 to your computer and use it in GitHub Desktop.
import paramiko
class SSHCommand:
def __init__(self, address, username, password):
print("Connecting to server on ip", str(address) + ".")
self._client = paramiko.client.SSHClient()
self._client.set_missing_host_key_policy(
paramiko.client.AutoAddPolicy())
self._client.connect(address, username=username, password=password,
look_for_keys=False)
def close(self):
self._client.close()
def send_cmd(self, cmd):
_, stdout, _ = self._client.exec_command(cmd)
buf = stdout.read()
return buf.decode("utf-8").replace('\r', '')
client = SSHCommand("localhost", ...)
data = client.send_cmd("ls /")
print(data)
data = client.send_cmd("ls /home")
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment