请注意,这在Windows中不起作用。
pxssh模块完全可以满足您的要求:
例如,运行’ls -l’并打印输出,您需要执行以下操作:
from pexpect import pxsshs = pxssh.pxssh()if not s.login ('localhost', 'myusername', 'mypassword'): print "SSH session failed on login." print str(s)else: print "SSH session login successful" s.sendline ('ls -l') s.prompt() # match the prompt print s.before # print everything before the prompt. s.logout()一些链接:
Pxssh文档:http : //dsnra.jpl.nasa.gov/software/Python/site-
packages/Contrib/pxssh.html
Pexpect(pxssh基于pexpect):http
://pexpect.readthedocs.io/ zh /稳定/



