Skip to content

Instantly share code, notes, and snippets.

@zhanglintc
Created November 1, 2018 14:43
Show Gist options
  • Save zhanglintc/3e26c6d3adf6734e63ca7c1d3120c5ee to your computer and use it in GitHub Desktop.
Save zhanglintc/3e26c6d3adf6734e63ca7c1d3120c5ee to your computer and use it in GitHub Desktop.
paramiko example
import paramiko
# create ssh clinet
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("domain", 22, "username", "password")
# execute ssh command
cmd = 'echo $HOSTNAME'
stdin, stdout, stderr = ssh.exec_command(cmd)
output = stdout.read()
print output
# create sftp client
sftp = ssh.open_sftp()
sftp.get("remote path", "local path")
sftp.put("local path", "remote path")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment