473,405 Members | 2,349 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.

using HTTP to download files from a secure (or unsecure) directory

Hey All,

I need to download 1 or more files from a secure or unsecure website
folder using HTTP.

Here is what I have so far:

public void GetHTTPImages()
{
WebClient HTTPClient = new WebClient();
HttpWebRequest webRequest;
HttpWebResponse webResponse;
Stream strResponse = null;
Stream strLocal = null;
bool isSuccessful = true;
string remoteFileName;
string localPath;
string serverAddress;
string uRL;
string destName;

GetFileToDownload(out remoteFileName,
out localPath,
out serverAddress);
try
{
while (remoteFileName != "")
{
uRL = serverAddress + remoteFileName;
destName = localPath+remoteFileName;

if (HTTPClient == null)
{
HTTPClient = new WebClient();
}

try
{
webRequest =
(HttpWebRequest)WebRequest.Create(uRL);
webRequest.Credentials =
CredentialCache.DefaultCredentials;
webResponse =
(HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
if (fileSize == 0)
{
//do not want a 0 byte file, get another filename
GetFileToDownload(out remoteFileName,
out localPath,
out serverAddress);
continue;
}
}
catch
{
MessageBox.Show(ex.Message);
isSuccessful = false;
}

try
{
if (isSuccessful)
{
strResponse =
HTTPClient.OpenRead(uRL);
strLocal =
new FileStream(destName,
FileMode.Create,
FileAccess.Write,
FileShare.None);
int bytesSize = 0;
byte[] downBuffer = new byte[2048];

// Loop through the buffer until the buffer is empty
while ((bytesSize =
strResponse.Read(downBuffer, 0,
downBuffer.Length)) 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
isSuccessful = false;
}

if (isSuccessful)
{
HttpWebRequest HttpWRequest =
(HttpWebRequest)WebRequest.Create(uRL);
HttpWRequest.Method = "DELETE";
webResponse =
(HttpWebResponse)HttpWRequest.GetResponse();
webResponse.Close();
}
}
}
finally
{
if (strResponse != null)
strResponse.Close();
if (strLocal != null)
strLocal.Close();
}
}

1) How do I log in to a secure folder?
2) Can I keep the session open so I don't have to keep
connecting/logging in?
3) Any thoughts on my code above?

Thank you very much!

~Gina~

Oct 28 '06 #1
3 3723
Hi Gina,

"Gina_Marano" <gi*******@gmail.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.com...
Hey All,

I need to download 1 or more files from a secure or unsecure website
folder using HTTP.

Here is what I have so far:

public void GetHTTPImages()
{
WebClient HTTPClient = new WebClient();
HttpWebRequest webRequest;
....
>
1) How do I log in to a secure folder?
What do you mean?
2) Can I keep the session open so I don't have to keep
connecting/logging in?
Create a CookieContainer instance and assign it to each HttpWebRequest.
3) Any thoughts on my code above?
Too much code to look :-)

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
Oct 29 '06 #2

Miha Markic [MVP C#] wrote:
1) How do I log in to a secure folder?

What do you mean?
When I use the web browswer and go to the URL the IE default login
dialog appears.
2) Can I keep the session open so I don't have to keep
connecting/logging in?

Create a CookieContainer instance and assign it to each HttpWebRequest.
thanks much Miha, I will look into the CookieContainer.
3) Any thoughts on my code above?

Too much code to look :-)
~Gina~

Oct 30 '06 #3
Hi Gina,

"Gina_Marano" <gi*******@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>
Miha Markic [MVP C#] wrote:
1) How do I log in to a secure folder?

What do you mean?

When I use the web browswer and go to the URL the IE default login
dialog appears.
Did you try setting HttpWebRequest.Credentials propery? (see help file)

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
Oct 31 '06 #4

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

Similar topics

10
by: scrimp | last post by:
Ive been using PAMIE 1.4 to try to automate web page processes. The one thing I cannot do with it is upload files and download files. With uploading files, the file input box does not allow PAMIE...
3
by: Derrick | last post by:
I have an http download that streams a zip file to client, after download I am getting "Error start of central directory not found; Zip file corrupt. Possible casue: file transfer error." Ring...
0
by: Owen Jenkins | last post by:
I've been using Dev's fantastic InetTransferLib to upload and download files via ftp. Now I'm using the http procedures to have my application download zip files from my website. Although the...
1
by: Owen Jenkins | last post by:
Reposting this message from last week since I have not had a reply so far. Hopefully someone will have an idea? --- I've been using Dev's fantastic InetTransferLib to upload and download files...
1
by: Poppy | last post by:
I have a webform which lists all files in a directory. When the user clicks on a file I want it to download. I know it is probably easy but I cannot figure it out. If I create a hyperlink...
6
by: Michael Tissington | last post by:
I have setup up Forms Authentication on my website and added configuration/mappings for exe, pdf and zip files (using C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll) However when...
1
by: rheigl | last post by:
I need a script to process all of the files in a directory (and sub-directories). Nearly all of the .ASX files have an out-of-date Copyright date. Example: <ASX version = "3.0"> <TITLE>Hello...
0
by: tanyali | last post by:
using php5, I download files : ******** downloadfile.php $fileContent = @mysql_result($result1,$i,"gdata"); ...
2
by: Mike P | last post by:
Is it possible to write some code to print to the screen a listing of all files within a directory? I want to show the path of each file on screen and enable the user to download any of the files....
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
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
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...

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.