Page 1 of 1

Data Download LP DAAC Data Pool via Java

Posted: Mon Jun 13, 2022 10:44 am America/New_York
by ryust
I've spent the last couple days going down different rabbit holes trying to find documentation and the method to just simply download a SRTM HGT file. For example, I want to get a file directly via its URL like "https://e4ftl01.cr.usgs.gov/MEASURES/SRTMGL3.003/2000.02.11/N09W062.SRTMGL3.hgt.zip" with a Java program. Each time I try I get a "HTTP Basic: Access denied" error. I have put my Earthdata login as part of the HTTP header "Authorization Basic" request property. I've tried various guesses as to what the format would be if the credentials were passed as parameters in the URL. Nothing works and I'm about to give up. Getting NASA data is crazy complex.

What is the way to pass Earthdata login credentials to directly download a granule file using Java?

Re: Data Download LP DAAC Data Pool via Java

Posted: Mon Jun 13, 2022 2:59 pm America/New_York
by LP DAAC - jwilson
We are sorry you are having some difficulties with your download. All downloads must have a Earthdata login to access the data. Our servers were having some issues which have been fixed. I was able to click on the link and successfully download the SRTM data.

I have forwarded your inquiry to our Subject Matter Expert for some guidance.

Data Prep Scripts can be found here: https://lpdaac.usgs.gov/tools/data-prep-scripts/
This collection of R and Python scripts can be used to download data and perform basic data processing functions such as georeferencing, reprojecting, converting, and reformatting data. Scripts are available in Python and/or R and each have a README that provides additional information. All scripts are available for download from the LP DAAC User Resources BitBucket Code Repository (https://git.earthdata.nasa.gov/projects/LPDUR).

Re: Data Download LP DAAC Data Pool via Java

Posted: Mon Jun 13, 2022 6:38 pm America/New_York
by ryust
Thanks for the reply.

I have tried the Java example here: https://wiki.earthdata.nasa.gov/display/EL/How+To+Access+Data+With+Java. I supply my Earthdata credentials as described in the sample code along with the granule URL in my previous post. The response back goes through 3 redirects (HTTP 302) to OAuth and then finally to a HTTP 403 login error. So what am I doing wrong?

A working example performing a download of one file would be great to see. Don't just click on a link once you are on a website with a previous authentication... I can do that also to get the download... but I would like to run a Java program outside of a browser to perform the download.

Re: Data Download LP DAAC Data Pool via Java

Posted: Mon Jun 20, 2022 2:21 pm America/New_York
by LP DAAC - afriesz
@ryust ,

We've taken a look at the Java code you linked to on the Earthdata Login wiki page (https://wiki.earthdata.nasa.gov/display/EL/How+To+Access+Data+With+Java). We were not able to replicate your error message. In fact, we were not able to download a valid .zip file using the Java code provided. The Java code was not developed nor is it maintained by the LP DAAC. We have passed on the issue on to the team responsible for that code, however, I do not have a time frame for its work. In the meantime I would recommend the resources we maintain in our BitBucket Code Repository (https://git.earthdata.nasa.gov/projects/LPDUR), which is primarily Python resources. Additionally, if you're looking for just downloads, we have resource for downloading using wget or cURL.

Re: Data Download LP DAAC Data Pool via Java

Posted: Mon Jun 20, 2022 6:00 pm America/New_York
by ryust
Through trial and error I found what would make the download work. In the sample Java code, remove the "connection.setDoOutput(true)" line from the program... then it should work.

Re: Data Download LP DAAC Data Pool via Java

Posted: Fri Jan 05, 2024 9:48 pm America/New_York
by ggc.nsidc
Does your java code still work. I have used the example code for several years to download
lots of data. Now it does not work. The server location has changed but the final file names are
still the same. I get several 302 status but when it reaches 301 status here is my error:
sun.net.www.protocol.https.DelegateHttpsURLConnection:https://data.lpdaac.earthdatacloud.nasa.gov/login?code=Pn6NQ0JFiVnz-dkLeZb2WEXvfDry_tSydhuHaEXvrCVA08G7M2YYydJc94fEu5t_wRzeMQ&state=%2Flp-prod-protected%2FMYD11_L2.061%2FMYD11_L2.A2003002.0550.061.2020133165743%2FMYD11_L2.A2003002.0550.061.2020133165743.hdf

ERROR: Failed to retrieve resource
java.net.MalformedURLException: no protocol: /lp-prod-protected/MYD11_L2.061/MYD11_L2.A2003002.0550.061.2020133165743/MYD11_L2.A2003002.0550.061.2020133165743.hdf
at java.base/java.net.URL.<init>(URL.java:772)
at java.base/java.net.URL.<init>(URL.java:654)
at java.base/java.net.URL.<init>(URL.java:590)
at CopyEarthdata.getResource(CopyEarthdata.java:107)
at CopyEarthdata.copy(CopyEarthdata.java:62)
at CopyEarthdata.main(CopyEarthdata.java:31)

I guess I have to go learn python to get something that works!!