1

Hello I am trying to just do simple read and write files from an a simple ftp file zilla server using passive mode and explicit tls I have setup that works fine with their file zilla client. I cannot figure out how to resolve this error when reading or writing. Commands to do other things like mkdir work fine as well

>>> 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)

I am using python3.5.2 on ubuntu 16.04. I have been looking over lots of cimilar questions, but non that seem to apply to ftp. All I can find is that python3 support explicit tls just fine. Any help is greatly appreciated.

noone392
  • 1,624
  • 3
  • 18
  • 30

1 Answers1

0

So I figured it out and this answer was not in any other thread I could fine. It turns our that the server had tls session reuse enabled for passive connections and that wasn't supported until python3.6. So I turned off the requirement and it worked fine. In filezilla it is called "Require TLS session resumption on data connections when using prot_p".

noone392
  • 1,624
  • 3
  • 18
  • 30