问题描述
我需要使用 SFTP 从主机下载文件.
I need to download a file from a host using SFTP.
你知道是否可以使用 Python ftplib 做到这一点?我看到了此处的示例,但是当我尝试连接时,收到 EOFError代码>.
Do you know if is it possible to do that using Python ftplib?I saw an example here, but when I try to connect I receive EOFError
.
我试过这个代码:
import ftplib
ftp = ftplib.FTP()
ftp.connect( "1.2.3.4", "22" )
此方法在很长时间后返回错误,因此我无法执行登录调用.我不能尝试构造函数 FTP([host[, user[, passwd[, acct[, timeout]]]]])
因为我的端口是 22,但 ftplib
默认是 21.
This method returns with an error after long time so I cannot perform a call to login.I cannot try the constructor FTP([host[, user[, passwd[, acct[, timeout]]]]])
becausemy port is 22 but ftplib
default is 21.
如果我按照这个例子
ftp = ftplib.FTP("1.2.3.4")
ftp = ftplib.FTP("1.2.3.4","22")
我收到连接被拒绝,因此我无法输入任何用户名密码.你能帮助我吗?非常感谢
I receive a connection refused so I cannot enter any username password. Can you help me? Thank you very much
推荐答案
As 你链接的问题 声明,ftplib 不支持 SFTP(这是一种通过 SSH 的传输协议,与 FTPS、FTP over SSL 无关).使用推荐Paramiko 代替.
As the question you linked to states, ftplib doesn't support SFTP (which is a transfer protocol over SSH and has nothing to do with FTPS, FTP over SSL). Use the recommended Paramiko instead.
这篇关于使用 ftplib 的 SFTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!