From 3fc992627cd5950d70473917a5388172bc089cdc Mon Sep 17 00:00:00 2001 From: Bob Garwood Date: Tue, 29 Oct 2024 17:16:40 -0400 Subject: [PATCH] change to use FTP_TLS instead of FTP --- casaconfig/private/measures_available.py | 16 ++++++++++------ casaconfig/private/measures_update.py | 18 +++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/casaconfig/private/measures_available.py b/casaconfig/private/measures_available.py index c4cde48..789f101 100644 --- a/casaconfig/private/measures_available.py +++ b/casaconfig/private/measures_available.py @@ -36,18 +36,22 @@ def measures_available(): - Exception: raised when any unexpected exception happens """ - from ftplib import FTP + from ftplib import FTP_TLS import socket from casaconfig import RemoteError files = [] try: - ftp = FTP('ftp.astron.nl') - rc = ftp.login() - rc = ftp.cwd('outgoing/Measures') - files = ftp.nlst() - ftp.quit() + ftps = FTP_TLS('ftp.astron.nl') + # this doesn't work + # rc = ftps.login() + # but this does, go figure + rc = ftps.sendcmd('USER anonymous') + rc = ftps.sendcmd('PASS anonymous') + rc = ftps.cwd('outgoing/Measures') + files = ftps.nlst() + ftps.quit() #files = [ff.replace('WSRT_Measures','').replace('.ztar','').replace('_','') for ff in files] files = [ff for ff in files if (len(ff) > 0) and (not ff.endswith('.dat'))] except socket.gaierror as gaierr: diff --git a/casaconfig/private/measures_update.py b/casaconfig/private/measures_update.py index a338330..cac33f1 100644 --- a/casaconfig/private/measures_update.py +++ b/casaconfig/private/measures_update.py @@ -129,7 +129,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda from datetime import datetime import sys - from ftplib import FTP + from ftplib import FTP_TLS import tarfile import re import ssl @@ -289,10 +289,14 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda print_log_messages(' ... connecting to ftp.astron.nl ...', logger) clean_lock = False - ftp = FTP('ftp.astron.nl') - rc = ftp.login() - rc = ftp.cwd('outgoing/Measures') - files = sorted([ff for ff in ftp.nlst() if (len(ff) > 0) and (not ff.endswith('.dat')) and (ftp.size(ff) > 0)]) + ftps = FTP_TLS('ftp.astron.nl') + # this doesn't work + # rc = ftps.login() + # but this does - go figure + rc = ftps.sendcmd('USER anonymous') + rc = ftps.sendcmd('PASS anonymous') + rc = ftps.cwd('outgoing/Measures') + files = sorted([ff for ff in ftps.nlst() if (len(ff) > 0) and (not ff.endswith('.dat')) and (ftps.size(ff) > 0)]) # target filename to download # for the non-force unspecified version case this can only get here if the age is > 1 day so there should be a newer version @@ -309,9 +313,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda with open(ztarPath, 'wb') as fid: print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger) - ftp.retrbinary('RETR ' + target, fid.write) + ftps.retrbinary('RETR ' + target, fid.write) - ftp.close() + ftps.close() # remove any existing measures readme.txt now in case something goes wrong during extraction readme_path = os.path.join(path,'geodetic/readme.txt')