Example Bash Script
When retrieving a selection of files from the MAST Portal, one option is to download an auto-generated bash (shell) script. These scripts use the cURL utility to retrieve the selected files. cURL is robust, reliable, and supports many features including authentication. It is also the preferred tool for downloading large volumes of data because of the data volume and rate limits imposed by the Portal Web interface.
If you would like to customize the example script provided here to access data files in MAST, you will first need to determine the URIs for the files of interest using another API, e.g., astroquery.mast.
Invoke the script in a unix terminal to download the files:
A look at the example script MAST_2022-04-30T2153.sh shows that, apart from some housekeeping, it does a few main things:
- For EAP protected data, fetch the MAST API Token
- Create a folder for the payload
- Create a
MANIFEST.HTMLfile to report status of the requested vs. retrieved data files
- Retrieve each data file with a cURL command
Items 1 and 4 are described below in more detail.
The API Token
If the requested files include at least one with EAP protection, a MAST API token is required. As the following code snippet shows, the MAST token may be supplied in multiple ways.
The following code snippet shows how each file is retrieved with cURL. For readability, the cURL command is re-formatted here as multi-line, with linux/MacOS escape characters.
It is worth calling out two important cURL command-line options:
-H: pass custom header to the server. In this case, the MAST auth token
--location-trusted: Follow re-directs, and send auth to other hosts