使用Python进行SSH的最简单方法是什么?
如何简单地从本地Python(3.0)脚本SSH到远程服务器,提供登录名/密码,执行命令并将输出打印到Python控制台?
How can I simply SSH to a remote server from a local Python (3.0) script, supply a login/password, execute a command and print the output to the Python console?
我宁愿不使用任何大型外部库或在远程服务器上安装任何东西.
I would rather not use any large external library or install anything on the remote server.
I haven't tried it, but this pysftp module might help, which in turn uses paramiko. I believe everything is client-side.
有趣的命令可能是.execute()
,它在远程计算机上执行任意命令. (该模块还具有.get()
和.put
方法,这更多地暗示了它的FTP字符).
The interesting command is probably .execute()
which executes an arbitrary command on the remote machine. (The module also features .get()
and .put
methods which allude more to its FTP character).
更新:
在我最初链接到的博客文章不再可用之后,我已经重新编写了答案.现在,某些引用此答案的旧版本的评论看起来很奇怪.
I've re-written the answer after the blog post I originally linked to is not available anymore. Some of the comments that refer to the old version of this answer will now look weird.