Page 1 of 1

C# Download SRTM HGT Files

Posted: Thu Jun 03, 2021 11:16 am America/New_York
by sisocano
Hi there,
I have a simple issue when i try to download HGT file from earthdata via unity+ C#

I'm Getting this Error :
WebException: The remote server returned an error: (401) Unauthorized.

Any Help would be grateful.

My Script :

using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using UnityEngine;

public class DownloadSRTM : MonoBehaviour
{
public string FileUrl = "https://e4ftl01.cr.usgs.gov/MEASURES/SR ... L1.hgt.zip";
public string User = "username";
public string Pass = "userpassword";
public string DownloadPath = @"D:\SRTM\srtm.zip";


// Start is called before the first frame update
async void Start()
{
await SRTMDownload();
}

// Update is called once per frame
void Update()
{

}
private async Task SRTMDownload()
{
var client = new WebClient();
client.Credentials = new NetworkCredential(User, Pass, "https://e4ftl01.cr.usgs.gov");
client.UseDefaultCredentials = true;
await client.DownloadFileTaskAsync(new Uri(FileUrl),DownloadPath);

}
}

Re: C# Download SRTM HGT Files

Posted: Thu Jun 03, 2021 2:54 pm America/New_York
by LP DAAC - jwilson
We have forwarded your inquiry to our Subject Matter expert for further guidance.

Re: C# Download SRTM HGT Files

Posted: Thu Jun 03, 2021 3:19 pm America/New_York
by sisocano
thanks for replay.

Re: C# Download SRTM HGT Files

Posted: Fri Jun 04, 2021 2:52 pm America/New_York
by LP DAAC - afriesz
@sisocano,

We may have to put out a call for someone more familiar with C#, but I did potentially notice something in your script. I think the URL in the following line is incorrect.

Code: Select all

client.Credentials = new NetworkCredential(User, Pass, "https://e4ftl01.cr.usgs.gov");
Try substituting "https://e4ftl01.cr.usgs.gov" with "urs.earthdata.nasa.gov".
Let us know if that works.

Re: C# Download SRTM HGT Files

Posted: Sat Jun 05, 2021 6:29 am America/New_York
by sisocano
Hi there,

Thanks for the quick replay, i have found a solution in that link.

https://wiki.earthdata.nasa.gov/pages/v ... d=76519934

Best Regards