I'm trying to fetch files from an FTP Server using implicit FTP over TLS. This works fine in Filezilla.
However, following code in Python 3.9.5
from ftplib import FTP_TLS
import ssl
import sys, os
ftps = FTP_TLS('xxx')
ftps.debugging = 5
ftps.login('yyy', 'zzz')
ftps.prot_p()
filenames = ftps.nlst()
for filename in filenames:
local_filename = os.path.join('./output/', filename)
file = open(local_filename, 'wb')
ftps.retrbinary('RETR '+ filename, file.write)
file.close()
ftps.quit()
Gives me the following Traceback
Traceback (most recent call last):
File "/home/epieters/repos/xxxx/yyyy.py", line 10, in <module>
filenames = ftps.nlst()
File "/home/epieters/.pyenv/versions/3.9.5/lib/python3.9/ftplib.py", line 553, in nlst
self.retrlines(cmd, files.append)
File "/home/epieters/.pyenv/versions/3.9.5/lib/python3.9/ftplib.py", line 479, in retrlines
conn.unwrap()
File "/home/epieters/.pyenv/versions/3.9.5/lib/python3.9/ssl.py", line 1285, in unwrap
s = self._sslobj.shutdown()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2756)
I really have no clue and tried multiple solutions suggested here on stackoverflow. Even when a call a simple ftps.retrlines('LIST') after ftps.prot_p(), I get the same SSL error.
Anybody out there that knows what I'm doing wrong?