使用Python ftplib完成FTPS传输后出错

2024-04-29 04:14:22 发布

您现在位置:Python中文网/ 问答频道 /正文

问候语

我尝试用以下脚本将文件上载到FTPS服务器(Wing FTP服务器/Cerberus FTP服务器8)。在

from ftplib import FTP_TLS
ftps = FTP_TLS('192.168.133.69')
ftps.login('1011', '7c52xK9')      
ftps.prot_p()
filename = 'upload.pdf'
myfile = open(filename, 'rb')
ftps.storbinary('STOR %s' % filename, myfile)
myfile.close()
ftps.close()

但我总是犯这个错误。在

^{pr2}$

这是FTPS服务器日志。在

[04] Thu, 02 Feb 2017 19:41:23 (0000062) 220 Wing FTP Server ready... (UNREGISTERED WING FTP SERVER)
[03] Thu, 02 Feb 2017 19:41:23 (0000062) AUTH TLS
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 234 AUTH command OK. Initializing TLS connection.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) USER 1011
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 331 Password required for 1011
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PASS **********
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 230 User 1011 logged in.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PBSZ 0
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 200 Command okay. PBSZ=0.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PROT P
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 200 Encrypting Data Channel.
[03] Thu, 02 Feb 2017 19:41:23 (0000062) TYPE I
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 200 Type set to I
[03] Thu, 02 Feb 2017 19:41:23 (0000062) PASV
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 227 Entering Passive Mode (192,168,133,69,4,21)
[03] Thu, 02 Feb 2017 19:41:23 (0000062) STOR upload.pdf
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 150 Opening BINARY mode data connection for file transfer.
[04] Thu, 02 Feb 2017 19:41:23 (0000062) 226 File received successful. Transferred:0Bytes;Average speed is:0.000KB/s

谁能告诉我怎么了?!!在

PS:我不知道这是否重要,但我可以很容易地从这个FTPS服务器下载,只有不能上传到它。在

提前谢谢

编辑1:

我按照“martinprikryl”的建议尝试使用FileZilla,现在我有以下错误。在

line 7, in <module>
    ftps.storbinary('STOR %s' % filename, myfile)
  File "C:\Python27\lib\ftplib.py", line 760, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "C:\Python27\lib\ftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python27\lib\ftplib.py", line 713, in ntransfercmd
    server_hostname=self.host)
  File "C:\Python27\lib\ssl.py", line 363, in wrap_socket
    _context=self)
  File "C:\Python27\lib\ssl.py", line 611, in __init__
    self.do_handshake()
  File "C:\Python27\lib\ssl.py", line 840, in do_handshake
    self._sslobj.do_handshake()
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:661)

这是FileZilla服务器日志。在

(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> Connected on port 21, sending welcome message...
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 220-FileZilla Server 0.9.59 beta
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 220 Please visit https://filezilla-project.org/
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> AUTH TLS
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 234 Using authentication type TLS
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> TLS connection established
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> USER 1011
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> 331 Password required for 1011
(000002)2017/02/03 11:00:54 ق.ظ - (not logged in) (127.0.0.1)> PASS *******
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 230 Logged on
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> PBSZ 0
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 200 PBSZ=0
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> PROT P
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 200 Protection level set to P
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> TYPE I
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 200 Type set to I
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> PASV
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 227 Entering Passive Mode (127,0,0,1,231,157)
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> STOR upload.pdf
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 150 Opening data channel for file upload to server of "/upload.pdf"
(000002)2017/02/03 11:00:54 ق.ظ - 1011 (127.0.0.1)> 450 TLS session of data connection has not resumed or the session does not match the control connection
(000002)2017/02/03 11:02:54 ق.ظ - 1011 (127.0.0.1)> 421 Connection timed out.
(000002)2017/02/03 11:02:54 ق.ظ - 1011 (127.0.0.1)> disconnected.

Tags: inpyself服务器liblinetlsnot
1条回答
网友
1楼 · 发布于 2024-04-29 04:14:22

可能是您和服务器之间的某个防火墙/NAT/proxy干扰了传输连接。在

由于问题似乎发生在TLS/SSL连接的断开过程中,在实际传输完成后,一些客户机可能只是选择忽略错误(或者他们甚至没有注意到)。在

相关问题 更多 >