Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download a file with password and username with C#

Tags:

c#

download

How would I write a script to download files from this site. Is it possible to supply the login and password with the url?

http://feeds.itunes.apple.com/feeds/epf/

Would I format the url like this?

WebClient Client = new WebClient();
Client.DownloadFile("http://feeds.itunes.apple.com/feeds/epf/v3/full/current/itunes20110511.tbz.md5?username=myusername&password=mypassword", @"C:\folder\file.md5");
like image 685
Arizona1911 Avatar asked May 17 '11 02:05

Arizona1911


2 Answers

Yes, just set the WebClient's Credentials property to a NetworkCredentials instance with the username/password. For example:

Client.Credentials = new System.Net.NetworkCredential("john", "password1234!");
like image 74
Drew Marsh Avatar answered Nov 20 '22 10:11

Drew Marsh


Use WebClient.Credentials property to supply your credentials to the web site:

using (WebClient client = new WebClient()) {
    client.Credentials = new NetworkCredential(username, password);
    client.DownloadFile("http://feeds.itunes.apple.com/feeds/epf/v3/full/current/itunes20110511.tbz.md5", @"C:\folder\file.md5");
}
like image 37
Andrew Savinykh Avatar answered Nov 20 '22 11:11

Andrew Savinykh