473,408 Members | 2,888 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,408 software developers and data experts.

Downloading a file from a server that requires a digital certifica

Not sure this is the right place to ask my question, please bear with me.
After reading the question, if you think there should be a different place
let me know.

I need to automate a daily download of a file from a server that requires a
digital certificate. I installed the certificate so now, when I try to access
the server with IE, a small window pops-up telling me that the "Web site I
want to view requests identification". I am prompted to select a digital
certificate and upon selecting the one I installed I gain access to the
remote folder and see the file that I want to downlad.
At someone's suggestion I looked at WebClient.DownloadFile, but that
obviously fails because I am not authorized to see the content of the folder
and the method will not take me to the UI where I need to select the digital
certificate. I fact I don't even need that step. As I said, I am trying to
automate the download and there should be no human input in the process.
I guess I need to somehow indicate that I want to use the respective digital
certificate when I create the web session. Is there a way this can be
achieved with the WebClient class or I need to look at a different class /
approach?

Thanks in advance for any suggestion and pardon me if this should have gone
on a different newsgroup.

Regards,
Eddie
Jul 9 '07 #1
1 1464
I figured it out. Here is the code that almost does it:
// obtain a collection of certificates
X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
collection = (X509Certificate2Collection)store.Certificates;
fcollection =
(X509Certificate2Collection)collection.Find(X509Fi ndType.FindByTimeValid,
DateTime.Now, false);

// URL for my file to download
string myFile2Get = "https://www.MySecureWebsite.com/MyFile.txt";

// create the specialized Web Request object
HttpWebRequest objHttpWebReq = WebRequest.Create(myFile2Get) as
HttpWebRequest;

// add the collection of the certificates
objHttpWebReq.ClientCertificates = fcollection;

// default method is GET

// get the response to my request
HttpWebResponse response = objHttpWebReq.GetResponse() as HttpWebResponse;

// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipes the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream = new StreamReader(receiveStream, encode);

The problem I am facing now is not related to this question and will be the
subject of a different post on this newsgroup.

Regards everyone,
Eddie
Jul 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Fitzjarrell | last post by:
omlet@omlet.org wrote in message news:<dc6c1ff0.0406300739.5001ae2a@posting.google.com>... > fitzjarrell@cox.net (David Fitzjarrell) wrote in message...
2
by: Brian Madsen | last post by:
Hey guys, I am currently working on a remote file upload utility from an external server to a local server. Problems I face is: 1)the request server cannot be mapped - ie. i can't secure it...
2
by: Steven | last post by:
I want my users to access my .aspx and hit a button to download a file. I tried using the a System.Net.Webclient object but instead of the file being downloaded to the users PC, its copied to the...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
2
by: Tomas Martinez | last post by:
Hi there! I'm trying to download a file in my asp.net web, but when downloading it from a Firefox browser, instead of downloading the example.exe file, it's downloading example.exe.htm. My code...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
2
by: gauravgeek | last post by:
Hi, I want to create a csv file on the fly and download it on client browser. I have all the content of csv file in a vb script variant variable. I created the csv file using textstream and FSO...
0
by: =?Utf-8?B?RWRkaWUgTGFzY3U=?= | last post by:
Hello everybody, I am struggling with this issue for a few days now. I need to create an automatic process to daily download a file from a server that requires a digital certificate. The...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.