Skip to content

Commit

Permalink
change to use FTP_TLS instead of FTP
Browse files Browse the repository at this point in the history
  • Loading branch information
bgarwood committed Oct 29, 2024
1 parent c550271 commit 3fc9926
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
16 changes: 10 additions & 6 deletions casaconfig/private/measures_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 11 additions & 7 deletions casaconfig/private/measures_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit 3fc9926

Please sign in to comment.