如何使用 m2crypto 在 FTPS 服务器上上传文件

发布于 2024-09-26 23:25:51 字数 1267 浏览 11 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫人生路 2024-10-03 23:25:51

解决方案是在 login() 之后显式调用受保护的传输:

ftp.prot_p()

Solution is to explicitly call for protected transfer after login():

ftp.prot_p()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文