如何使用 python 3.6 从 SFTP 传输文件 [英] How can I transfer file from SFTP using python 3.6
问题描述
我想在 Python 3.6 中使用 paramiko 进行 SFTP 文件传输.我知道 paramiko 依赖于 PyCrypto 并且已经阅读了 Python 3.6 中的 PyCrypto 安装问题.虽然我看到了很多关于这个主题的问题,但我还没有找到在 Python 3.6 中成功传输 SFTP 文件的解决方案.
I would like to use paramiko for SFTP file transfer in Python 3.6. I know that paramiko depends on PyCrypto and have read about PyCrypto installation problems in Python 3.6. Although I have seen a number of questions regarding this topic, I have not found a solution to successful SFTP file transfer in Python 3.6.
我的第一个问题:是否可以使用 Python 3.6 进行 SFTP 文件传输?如果是这样,paramiko 会起作用吗?如果上述方法可行,为什么我在尝试安装 PyCrypto 时会收到以下错误?
My first question: is it possible to use Python 3.6 for SFTP file transfer? If so, will paramiko work? If the above will work, why I am I receiving the following errors when attempting to install PyCrypto?
error: [WinError 2] The system canot find the file specified
**Failed building wheel for pycrypto**
我的第二个问题:如果 paramiko 不能与 Python 3.6 一起使用,是否有其他选择,或者我必须恢复到以前的 Python 版本以进行 SFTP 文件传输?
My second question: if paramiko will not work with Python 3.6, are there any alternatives or must I revert back to a previous python version for SFTP file transfer?
推荐答案
是的,通过 python 可以使用 sftp 进行文件传输.Python 有一个不错的包
Yes through python can possible to file transfer with sftp. Python has a nice package
第 1 步:
pip install pysftp
第 2 步:
文件传输示例:
import pysftp
with pysftp.Connection('hostname', username='me', password='secret') as sftp:
with sftp.cd('public'): # temporarily chdir to public
sftp.put('/my/local/filename') # upload file to public/ on remote
sftp.get('remote_file') # get a remote file
这篇关于如何使用 python 3.6 从 SFTP 传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!