Skip to content

Instantly share code, notes, and snippets.

@anselal
Created October 23, 2017 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anselal/6b147467b528a839a12b7665bce69f8d to your computer and use it in GitHub Desktop.
Save anselal/6b147467b528a839a12b7665bce69f8d to your computer and use it in GitHub Desktop.
[Python] paramiko
# SFTP
import paramiko
channel = paramiko.Transport(('host', 22))
channel.connect(username='username', password='password')
client = paramiko.SFTPClient.from_transport(channel)
client.chdir('/tmp')
print(client.getcwd())
cmd = client.sock.transport.open_session()
cmd.exec_command('ls -l')
cmdout = cmd.makefile('rb', -1).readlines()
cmderr = cmd.makefile_stderr('rb', -1).readlines()
print(cmdout, cmderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment