Question

I've been looking around for a module which allows me to do SSH / SFTP functions in python without using POPEN to do it manually. Is there anything like this? I haven't found any real information on this, thanks!

Was it helpful?

Solution

You're probably looking for the excellent paramiko library:

http://www.paramiko.org/

OTHER TIPS

paramiko works nicely: Paramiko Homepage

For SFTP, you can use pysftp, which is a thin wrapper over paramiko's SFTPClient (pip install sftp).

Example to download a file:

import pysftp #pip install sftp
import sys

hostname = "128.65.45.12"
username = "bob"       
password = "123456"  

sftp = pysftp.Connection(hostname, username=username, password=password)

sftp.get('/data/word_vectors/GoogleNews-vectors-negative300.txt', preserve_mtime=True)
print('done')

Depending on what you're looking to do over ssh, you might also benefit from looking at the pexpect library: http://www.noah.org/wiki/pexpect

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top