如何使用 m2crypto 在 FTPS 服务器上上传文件
我正在尝试使用 ftps 将文件上传到我们的 FTP 服务器。登录很简单并且有效:
from M2Crypto import ftpslib
ftp = ftpslib.FTP_TLS()
ftp.connect(host)
ftp.login(username, password)
以及下降到目录
for dir in directory:
ftp.cwd(dir)
但是,当尝试检索目录内容时:
if directory_name not in ftp.nlst():
ftp.mkd(directory_name)
我收到 522 错误:
File "/usr/lib/python2.5/ftplib.py", line 459, in nlst
self.retrlines(cmd, files.append)
File "/usr/lib/python2.5/ftplib.py", line 407, in retrlines
conn = self.transfercmd(cmd)
File "/usr/lib/python2.5/ftplib.py", line 356, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/var/lib/python-support/python2.5/M2Crypto/ftpslib.py", line 86, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
File "/usr/lib/python2.5/ftplib.py", line 327, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/lib/python2.5/ftplib.py", line 241, in sendcmd
return self.getresp()
File "/usr/lib/python2.5/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 522 Data connections must be encrypted.
似乎 TLS 仅用于握手,而不用于传输。
有没有一种方法可以使用 M2Crypto 来保护传输(我想使用 storbinary()
上传文件)?如果没有,还有什么其他选择?
I am trying to use ftps to upload file to our FTP server. Login is trivial and works:
from M2Crypto import ftpslib
ftp = ftpslib.FTP_TLS()
ftp.connect(host)
ftp.login(username, password)
as well as descending into directory
for dir in directory:
ftp.cwd(dir)
However, when trying to retrieve directory content:
if directory_name not in ftp.nlst():
ftp.mkd(directory_name)
I get 522 error:
File "/usr/lib/python2.5/ftplib.py", line 459, in nlst
self.retrlines(cmd, files.append)
File "/usr/lib/python2.5/ftplib.py", line 407, in retrlines
conn = self.transfercmd(cmd)
File "/usr/lib/python2.5/ftplib.py", line 356, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/var/lib/python-support/python2.5/M2Crypto/ftpslib.py", line 86, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
File "/usr/lib/python2.5/ftplib.py", line 327, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/lib/python2.5/ftplib.py", line 241, in sendcmd
return self.getresp()
File "/usr/lib/python2.5/ftplib.py", line 216, in getresp
raise error_perm, resp
ftplib.error_perm: 522 Data connections must be encrypted.
It seems TLS is used only for handshake, not for transfers.
It there a way to secure the transfer (I'd like to upload files using storbinary()
) using M2Crypto? If not, what are other alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是在
login()
之后显式调用受保护的传输:Solution is to explicitly call for protected transfer after
login()
: