如何连接到 FTPS 服务器并在其中下载文件? 目前我正在使用以下代码在使用 Docker 构建的 FTPS 服务器中检索一些文件。
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
我的问题如下:
我在网上找不到任何完整的代码示例或解释,任何人都可以帮助我吗?