how can I connect to an FTPS server and download files in it? Currently I am using the following code to retrieve some files in FTPS Server built with Docker.
import ftplib
import os
from dateutil import parser
from datetime import datetime
def connect(host, port, user, password):
ftp = ftplib.FTP_TLS()
ftp.debugging = 2
ftp.connect(host, port)
ftp.login(user, password)
return ftp
def retrieveFileList(ftp, ftp_paths, fileType, destinationPath, date):
total_files = []
timestamps = []
for path in ftp_paths:
currentPath = os.getcwd()
os.chdir(destinationPath)
ftp.cwd(path)
files = ftp.nlst('*'+ fileType)
for file in files:
timestamp = ftp.voidcmd("MDTM " + file)[4:].strip()
time = parser.parse(timestamp)
parsed_time = time.strftime("%Y-%m")
timestamps.append(parsed_time)
if not date > parsed_time:
total_files.append(file)
with open(file, 'wb') as f:
ftp.retrbinary('RETR ' + file, f.write)
os.chdir(currentPath)
max_timestamp = max(timestamps)
return total_files, max_timestamp
My questions are the following:
- Do I have to verify server certificate?
- Do I have to create an SSL context and pass it as parameter in FTP_TLS()
- Do I need a certificate (client certificate) in order to connect to the server?
I cannot find any complete code example or explanation online, can anyone help me?