Python SSH/SFTP 模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1603984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:40:57  来源:igfitidea点击:

Python SSH / SFTP Module?

pythonsshsftp

提问by rdegges

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!

我一直在寻找一个模块,它允许我在 python 中执行 SSH/SFTP 功能,而无需使用 POPEN 手动完成。有这样的吗?我还没有找到这方面的任何真实信息,谢谢!

回答by Carl Hill

You're probably looking for the excellent paramiko library:

您可能正在寻找优秀的 paramiko 库:

http://www.paramiko.org/

http://www.paramiko.org/

回答by Ringding

paramiko works nicely: Paramiko Homepage

paramiko 工作得很好:Paramiko主页

回答by Franck Dernoncourt

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

对于 SFTP,您可以使用pysftp,它是 paramiko 的 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')

回答by Cole Tuininga

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

根据您希望通过 ssh 执行的操作,您可能还可以从查看 pexpect 库中受益:http://www.noah.org/wiki/pexpect