C# Download SRTM HGT Files

Please enter here to ask a question about any NASA Science related topics!
Post Reply
sisocano
Posts: 3
Joined: Thu Jun 03, 2021 10:34 am America/New_York

C# Download SRTM HGT Files

by sisocano » Thu Jun 03, 2021 11:16 am America/New_York

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);

}
}

Tags:

LP DAAC - jwilson
User Services
User Services
Posts: 57
Joined: Mon Sep 30, 2019 12:39 pm America/New_York
Answers: 1

Re: C# Download SRTM HGT Files

by LP DAAC - jwilson » Thu Jun 03, 2021 2:54 pm America/New_York

We have forwarded your inquiry to our Subject Matter expert for further guidance.

sisocano
Posts: 3
Joined: Thu Jun 03, 2021 10:34 am America/New_York

Re: C# Download SRTM HGT Files

by sisocano » Thu Jun 03, 2021 3:19 pm America/New_York

thanks for replay.

LP DAAC - afriesz
Subject Matter Expert
Subject Matter Expert
Posts: 5
Joined: Tue Nov 12, 2019 4:02 pm America/New_York

Re: C# Download SRTM HGT Files

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

@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.

sisocano
Posts: 3
Joined: Thu Jun 03, 2021 10:34 am America/New_York

Re: C# Download SRTM HGT Files

by sisocano » Sat Jun 05, 2021 6:29 am America/New_York

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

Post Reply