diff --git a/pyspedas/projects/themis/config.py b/pyspedas/projects/themis/config.py index abb00763..a881fa3c 100644 --- a/pyspedas/projects/themis/config.py +++ b/pyspedas/projects/themis/config.py @@ -1,7 +1,7 @@ import os CONFIG = {'local_data_dir': 'themis_data/', - 'remote_data_dir': 'http://themis.ssl.berkeley.edu/data/themis/'} + 'remote_data_dir': 'https://themis.ssl.berkeley.edu/data/themis/'} # override local data directory with environment variables if os.environ.get('SPEDAS_DATA_DIR'): diff --git a/pyspedas/utilities/download.py b/pyspedas/utilities/download.py index 5c848094..164fd7cd 100644 --- a/pyspedas/utilities/download.py +++ b/pyspedas/utilities/download.py @@ -225,7 +225,8 @@ def download_file( return None if needs_to_download_file: - ftmp = NamedTemporaryFile(delete=False) + froot, fsuffix = os.path.splitext(filename) + ftmp = NamedTemporaryFile(delete=False, suffix=fsuffix) with open(ftmp.name, "wb") as f: if text_only: @@ -241,13 +242,18 @@ def download_file( os.makedirs(os.path.dirname(filename)) # if the download was successful, copy to data directory - copy(ftmp.name, filename) + if check_downloaded_file(ftmp.name): + copy(ftmp.name, filename) + logging.info("Download complete: " + filename) + else: + logging.error("Download of '" + filename + "' failed. The temp file will be removed.") + logging.error("If the same file has been already downloaded previously, it might be possible to use that instead.") + # cleanup fsrc.close() ftmp.close() os.unlink(ftmp.name) # delete the temporary file - - logging.info("Download complete: " + filename) + # At this point, we check if the file can be opened. # If it cannot be opened, we delete the file and try again.