question

ThirstonThird-6499 avatar image
0 Votes"
ThirstonThird-6499 asked AgaveJoe edited

Download File Credentials

How do you download a file using a service account?

string uri = "https://nvd.nist.gov/download/nvd-rss.xml";
using (WebClient client = new WebClient())
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
client.DownloadFile(uri, @"c:\test\nvd-rss.xml");
}

dotnet-csharpsql-server-integration-services
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

vb2ae avatar image
0 Votes"
vb2ae answered AgaveJoe edited

The WebClient has a credentials property you can set when making a call if you want the call to use a specific credential

https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.credentials?view=net-6.0

  client.Credentials = new NetworkCredential(SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain);
  client.DownloadFile(uri, @"c:\test\nvd-rss.xml");
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Service accounts don't have a password and it doesn't work when the password is left blank. Unauthorized

0 Votes 0 ·
AgaveJoe avatar image AgaveJoe ThirstonThird-6499 ·

That's not totally correct. Predefined services accounts do not have passwords. You tagged this post as SSIS. Are you executing an SSIS package and having a problem? Is the code an executable? Why do you need a service account?

Anyway, I dropped URL in a browser and it return an XML stream. So the URL does not require any security that I can see.

0 Votes 0 ·
YitzhakKhabinsky-0887 avatar image
0 Votes"
YitzhakKhabinsky-0887 answered YitzhakKhabinsky-0887 edited

Hi @ThirstonThird-6499,

Please try the following solution.
It will work for any *.xml file.

c#

 void Main()
 {
  const string uri = "https://nvd.nist.gov/download/nvd-rss.xml";
  const string fileSaveAs = @"e:\temp\nvd-rss.xml";
    
  System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
    
  XDocument xdoc = XDocument.Load(uri);
  xdoc.Save(fileSaveAs);
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.