Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Downloading a file from a server that requires a digital certifica

Reply
Thread Tools

Downloading a file from a server that requires a digital certifica

 
 
=?Utf-8?B?RWRkaWUgTGFzY3U=?=
Guest
Posts: n/a
 
      07-09-2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWRkaWUgTGFzY3U=?=
Guest
Posts: n/a
 
      07-10-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Re: A question regarding Advent Computer Training - MCSE Certifica Michael D. Alligood [CertGuard, Inc.] MCSE 0 04-25-2008 03:24 PM
Re: A question regarding Advent Computer Training - MCSE Certifica Michael D. Alligood [CertGuard, Inc.] MCSE 14 04-25-2008 02:07 AM
Re: A question regarding Advent Computer Training - MCSE Certifica Michael D. Alligood [CertGuard, Inc.] MCSE 0 04-24-2008 08:01 PM
Re: A question regarding Advent Computer Training - MCSE Certifica Michael D. Alligood [CertGuard, Inc.] MCSE 0 04-23-2008 11:31 PM



Advertisments