Created
November 1, 2018 14:43
-
-
Save zhanglintc/3e26c6d3adf6734e63ca7c1d3120c5ee to your computer and use it in GitHub Desktop.
paramiko example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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