473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Unable to download file fdrom an authenticated website

Hi,

I am trying to build a c# apllication that should log in to a site and download files. I'm using WebClient.DownoadFile() method to accomplish this.

Here is the code snippet:

using (WebClient wc = new WebClient())
{
wc.BaseAddress = "https://www.alabama.com/incoming/";

string username = "user";
string password = "play";
wc.Credentials = new NetworkCredential (username, password);
wc.DownloadFile ("https://www.alabama.com/incoming/guestbook.txt", "guestbook.txt");

}

After the execution of the above block, when I check for the content of the downloaded file, I see the html scripts for the log in page and not the actual file content. Basically it is not logging in. Can somenoe let me know why is it so? Is there any other alternate method to download files from a site that requires user authentication?
Jan 14 '11 #1
3 2519
Plater
7,872 Expert 4TB
If there is a login page, then it is probably not using webauthentication.
The request cannot just magically fill in the form for you.
You are going to have to generate the log in request, parse the response and send back any cookies/session-cookies before you can download what you are after
Jan 14 '11 #2
Thanks Plater.

I am new to .net. Can you please tell me how this can be done?
Jan 15 '11 #3
Plater
7,872 Expert 4TB
Take a look at the HttpWebRequest object. You will probably need to use a few transactions from that to get the job done
Jan 17 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Chris Morrison | last post by:
Hi all, Can anyone tell me which .NET class I need (or provide a code sample) to download file from a website/url (Not FTP) and save it to my hard drive. Kind regards, Chris
0
by: Ilia Makarenko | last post by:
Hi everyone! I've got a problem with IIS 6.0 when downloading files with size > 4 Mb. So I am trying to download file in chunks, but it doesn't work. Only pert of the file is downloaded (~6.5 of...
1
by: Sam | last post by:
Hello everyone, WebClient object works very well with the no-need-to-authentication website. Can it also work also with authentication website? Thanks in advance. Sam
4
by: who be dat? | last post by:
I feel stupid for asking this but I can't figure this out. I've got some text files I want my website to read. The text files are located in a subdirectory of my application. Physically, the...
1
by: user2008 | last post by:
Hi all, I want to track how many times visitor download file from my website, for example, when visitor click on a download link, a ASPX page will be requested, after that it will redirect to a...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
0
by: Boris Twila | last post by:
Hi, what are the pros and cons? I'm doing a classified ads site, kinda based on craigslist. Craiglist is very file system-based. Other similar sites are not. I'm thinking of moving away...
3
by: cypherkro | last post by:
Hi I have a requirement to automatically download a file using a WebBrowser control without having the "Download File" pop up windows display. I cannot use Webclient!! I am using VS2005, .net2...
5
by: vinodkus | last post by:
dear sir/madam I have to write a code for download file using asp. please help me thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.