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

HTTPS File Downloader

I have been looking all over the web for an example of how to accomplish this. I am trying to download a comma seperated file from a https server. I can't establish the connection - the error reads

System.Net.WebException: The underlying connection was closed: Could not establish secure channel for SSL/TLS. ---> System.ComponentModel.Win32Exception: The function completed successfully, but must be called again to complete the contex

Here is the code to execute the file download

NetworkCredential cred = new NetworkCredential("user", "pass")
ServicePointManager.CertificatePolicy = new CertPolicy()

tr

WebRequest request = WebRequest.Create("https://securesite.com/file.csv")
request.Credentials = cred

WebResponse response = request.GetResponse()
Stream stream = response.GetResponseStream()

StreamReader reader = null
reader = new StreamReader(stream)
catch (Exception ex

this.txtError.Text = ex.ToString()

class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
{
return true;
}
}

Any help on this would greatly be appreciated. Also - any books that anyone could reccommend on this type of programming would be appreciated
Thanks - Drew
Nov 16 '05 #1
4 6232
Drew,

Have you been able to get the file just by using your browser and pointing
to the link you specify?

Since you are specifying a certificate policy I am unsure what you are
trying to accomplish. Have you exchanged a cert with your host server?
What are the settings in IIS for the HTTPS virtual directory?

I recently completed a communications package using certs so I will try to
help with your problem but I need the above information if possible.

Thanks,

Matt

"Drew" <dr*******@yahoo.com> wrote in message
news:E6**********************************@microsof t.com...
I have been looking all over the web for an example of how to accomplish this. I am trying to download a comma seperated file from a https server.
I can't establish the connection - the error reads:
System.Net.WebException: The underlying connection was closed: Could not establish secure channel for SSL/TLS. --->
System.ComponentModel.Win32Exception: The function completed successfully,
but must be called again to complete the context
Here is the code to execute the file download:

NetworkCredential cred = new NetworkCredential("user", "pass");
ServicePointManager.CertificatePolicy = new CertPolicy();

try
{
WebRequest request = WebRequest.Create("https://securesite.com/file.csv");
request.Credentials = cred;

WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();

StreamReader reader = null;
reader = new StreamReader(stream);

}
catch (Exception ex)
{
this.txtError.Text = ex.ToString();
}

}
class CertPolicy: ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) {
return true;
}
}

Any help on this would greatly be appreciated. Also - any books that anyone could reccommend on this type of programming would be appreciated. Thanks - Drew

Nov 16 '05 #2
Drew,

Yes what you want to do can be done. The reason I was asking about the
browser is that I wanted you to make sure it could be retrieved by some form
and not fight an IIS setting.

I have to say I have never seen a HTTPS request cause a login dialog box but
I am sure it's possible. I need you to tell me what your IIS settings are
for the virtual directory where the file is to be retrieved so I can mirror
them in my environment. I will need to play with some code I have to see if
I can get this working then I will be happy to turn it over to you. Is the
site public by chance so I can try to get to it from my workstation?

Thanks,

Matt
"Drew" <dr*******@yahoo.com> wrote in message
news:37**********************************@microsof t.com...
I am trying to download the file without having to go through the broswer everytime. I am essentially trying to make the download automated (about
every mintutes) so I can parse through and extract the proper info. I have
read all over the internet for an example and the code listed in the first
post is what I came up with. Here is what I do to get the info now through
a browser - 1. type in the https://website/file.csv
2. a windows login prompt comes up
3. I input the user/pass
4. the file is downloaded to a place of my choosing

I want the application to handle of this for me. I really have no clue about the certificate policy - that is from a post I found somehwere else.
I am not sure how/if I have exchanged a cert with host server - how can I
tell. I am completely new to this type of download process.
Can what I want be done?

Thanks for your help....
- Drew

Nov 16 '05 #3
You should just need to attach NetworkCredential's to your request.
You'll have to hard-code the credentials into your application, which can
be bad, but that is the only way to thwart the login dialog. You are getting
the dialog because settings on your file or IIS don't allow anonymous access
to the CSV file. If hard-coding credentials is out of the question, then you
will have to re-think your security and provide another way for your app to
access the file.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Matt" <md*****@sorvive.DONT-SEND-SPAM.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Drew,

Yes what you want to do can be done. The reason I was asking about the
browser is that I wanted you to make sure it could be retrieved by some form
and not fight an IIS setting.

I have to say I have never seen a HTTPS request cause a login dialog box but
I am sure it's possible. I need you to tell me what your IIS settings are
for the virtual directory where the file is to be retrieved so I can mirror
them in my environment. I will need to play with some code I have to see if
I can get this working then I will be happy to turn it over to you. Is the
site public by chance so I can try to get to it from my workstation?

Thanks,

Matt
"Drew" <dr*******@yahoo.com> wrote in message
news:37**********************************@microsof t.com...
I am trying to download the file without having to go through the broswer

everytime. I am essentially trying to make the download automated (about
every mintutes) so I can parse through and extract the proper info. I have
read all over the internet for an example and the code listed in the first
post is what I came up with. Here is what I do to get the info now through
a browser -
1. type in the https://website/file.csv
2. a windows login prompt comes up
3. I input the user/pass
4. the file is downloaded to a place of my choosing

I want the application to handle of this for me. I really have no clue

about the certificate policy - that is from a post I found somehwere else.
I am not sure how/if I have exchanged a cert with host server - how can I
tell. I am completely new to this type of download process.

Can what I want be done?

Thanks for your help....
- Drew


Nov 16 '05 #4
Drew,

Sounds strange.

Our email system went down right after I sent you the solution. I will let
you know when it's available.

Is your site public so I could work with you on this?

Thanks,

Matt

"Drew" <dr*******@yahoo.com> wrote in message
news:64**********************************@microsof t.com...
Matt -

I tried emailing to you but it was returned. I tried your solution and it gives the same security error without the second function part. There must
be a way to do this. I found an application called Net Vampire that I can
schedule to do the download every minute. But - I would still like to
figure this out so I could have everything running together.
thanks - drew

Nov 16 '05 #5

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

Similar topics

1
by: Phillip | last post by:
Hi. I'm having some anoying trouble trying to establish a https connection. I've even switched Python Versions (from 2.2.3 to 2.3.3), but the Errors remain basically the same, allthough they now...
0
by: Robert | last post by:
did you solve this problem? It seems to be still present here with py2.3.5. Robert -- From: Manish Jethani <manish.j@gmx.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;...
2
by: Mark Delon | last post by:
Hi, i want to log via python script to https page: 'https://brokerjet.ecetra.com/at/' # But it does not work. I am using following code(see below)
2
by: Gregory Hassett | last post by:
Hello, I am using the BITS downloader to retrieve a file as part of a self-updating application. The file is called xyz.dll -- and when BITS tries to get it from its location (where it's...
1
by: Tarren | last post by:
Hi there: I have figured out how to take the uploaded file from the form input and save it into the database, but I am wondering (and looking for examples) how can I stream the image back to the...
0
by: brian.fairchild | last post by:
I have a downloader page in my asp.net application that looks at a session variable to get the path to the file, checks it then downloads it using the Response object. When the "File Download"...
3
by: Paul Porthouse | last post by:
Hi. I have successfully written an automatic file downloader in VB.NET using webrequest but I can't find any information anywhere on how to read in the filename that the server is sending. ...
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: hydroniumf | last post by:
Hi Friends I search a good downloader with high speed that I can add my download URLs list in it via programming in .net. I mean I can control that downloader software via programing (adding list...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.