Downloading a file from a server that requires a digital certifica

Discussion in 'ASP .Net' started by =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 9, 2007.

  1. 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
     
    =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 9, 2007
    #1
    1. Advertisements

  2. 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(X509FindType.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
     
    =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 10, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9jZWx5biBEdWhheWx1bmdzb2Q=?=

    Receive server error while downloading file using Response.BinaryW

    =?Utf-8?B?Sm9jZWx5biBEdWhheWx1bmdzb2Q=?=, Jan 17, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    5,561
    =?Utf-8?B?Sm9jZWx5biBEdWhheWx1bmdzb2Q=?=
    Jan 17, 2005
  2. Replies:
    1
    Views:
    467
    Joerg Jooss
    Dec 3, 2005
  3. =?Utf-8?B?RnJhbms=?=

    downloading file get empty from one server.

    =?Utf-8?B?RnJhbms=?=, Dec 5, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    635
    =?Utf-8?B?RnJhbms=?=
    Dec 7, 2005
  4. Sam Thao
    Replies:
    0
    Views:
    481
    Sam Thao
    Sep 2, 2004
  5. =?ISO-8859-1?Q?Xaver_S=FCnkeler?=

    Downloading a file from an ftp server

    =?ISO-8859-1?Q?Xaver_S=FCnkeler?=, May 28, 2006, in forum: Java
    Replies:
    5
    Views:
    559
    =?ISO-8859-1?Q?Xaver_S=FCnkeler?=
    May 30, 2006
  6. =?Utf-8?B?RWRkaWUgTGFzY3U=?=

    Downloading a file from a website requesting a digital certificate

    =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 10, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    455
    =?Utf-8?B?RWRkaWUgTGFzY3U=?=
    Jul 10, 2007
  7. Steven Burn
    Replies:
    10
    Views:
    568
    Rodd Snook
    May 27, 2004
  8. mto32
    Replies:
    0
    Views:
    241
    mto32
    Mar 24, 2009
Loading...