您好我正在尝试使用被动模式和显式tls从一个简单的ftp文件zilla服务器上做简单的读写文件我已经设置了与他们的文件zilla客户端一起正常工作。我无法弄清楚如何在读或写时解决此错误。执行其他操作的命令如mkdir也可以正常工作
>>> from ftplib import FTP_TLS
>>> import subprocess
>>> import io
>>> import os
>>> import sys
>>> from datetime import datetime, date, time
>>> from os.path import basename
>>> local_filename = os.path.join(os.getcwd(), 'KansasCityTestData.csv')
>>> print(local_filename)
/var/www/KansasCityTestData.csv
>>> myfile = open(local_filename, 'wb')
>>> myfile
<_io.BufferedWriter name='/var/www/KansasCityTestData.csv'>
>>> command = 'RETR /%s' % 'KansasCityTestData.csv'
>>> command
'RETR /KansasCityTestData.csv'
>>> ftp = FTP_TLS('111.111.111.111') #except my real info
>>> ftp.login('myuser', 'mypass')
'230 Logged on'
>>> ftp.prot_p()
'200 Protection level set to P'
>>> ftp.set_pasv(True)
>>> ftp.retrbinary(command, myfile.write)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/ftplib.py", line 441, in retrbinary
with self.transfercmd(cmd, rest) as conn:
File "/usr/lib/python3.5/ftplib.py", line 398, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python3.5/ftplib.py", line 796, in ntransfercmd
server_hostname=self.host)
File "/usr/lib/python3.5/ssl.py", line 377, in wrap_socket
_context=self)
File "/usr/lib/python3.5/ssl.py", line 752, in __init__
self.do_handshake()
File "/usr/lib/python3.5/ssl.py", line 988, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib/python3.5/ssl.py", line 633, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:645)
我在ubuntu 16.04上使用python3.5.2。我一直在寻找许多类似的问题,但非似乎适用于ftp。我能找到的就是python3支持显式tls就好了。非常感谢任何帮助。
答案 0 :(得分:0)
所以我想出来了,这个答案不在任何其他线程我可以。我们认为服务器已经为被动连接启用了会话重用,并且在python3.6之前不支持。所以我关闭了要求并且工作正常。在filezilla中调用它 &#34;使用prot_p&#34;时需要在数据连接上恢复TLS会话。