Created
October 23, 2017 10:40
-
-
Save anselal/6b147467b528a839a12b7665bce69f8d to your computer and use it in GitHub Desktop.
[Python] paramiko
This file contains 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
# 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