473,811 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;

GetFileToDownlo ad(out remoteFileName,
out localPath,
out serverAddress);
try
{
while (remoteFileName != "")
{
uRL = serverAddress + remoteFileName;
destName = localPath+remot eFileName;

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

try
{
webRequest =
(HttpWebRequest )WebRequest.Cre ate(uRL);
webRequest.Cred entials =
CredentialCache .DefaultCredent ials;
webResponse =
(HttpWebRespons e)webRequest.Ge tResponse();
Int64 fileSize = webResponse.Con tentLength;
if (fileSize == 0)
{
//do not want a 0 byte file, get another filename
GetFileToDownlo ad(out remoteFileName,
out localPath,
out serverAddress);
continue;
}
}
catch
{
MessageBox.Show (ex.Message);
isSuccessful = false;
}

try
{
if (isSuccessful)
{
strResponse =
HTTPClient.Open Read(uRL);
strLocal =
new FileStream(dest Name,
FileMode.Create ,
FileAccess.Writ e,
FileShare.None) ;
int bytesSize = 0;
byte[] downBuffer = new byte[2048];

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

if (isSuccessful)
{
HttpWebRequest HttpWRequest =
(HttpWebRequest )WebRequest.Cre ate(uRL);
HttpWRequest.Me thod = "DELETE";
webResponse =
(HttpWebRespons e)HttpWRequest. GetResponse();
webResponse.Clo se();
}
}
}
finally
{
if (strResponse != null)
strResponse.Clo se();
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 3743
Hi Gina,

"Gina_Maran o" <gi*******@gmai l.comwrote in message
news:11******** **************@ e64g2000cwd.goo glegroups.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_Maran o" <gi*******@gmai l.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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
3234
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 to enter in a path to a file. With downloading files, I can click on the link to download the file, but thats where I get stuck at. It brings up that download window and then it brings up the where to save window.
3
9044
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 any bells? Here's the asp code, thanks in advance!! Derrick ... Response.ContentType = "application/zip"
0
1511
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 download process works OK, it adds a few bytes to the file during the download, so a 46k file becomes 52k. I can still open the file using Winzip, but cannot open it using my active X extraction system (ActiveXZip from www.hdse.com). I get an error...
1
2258
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 via ftp. Now I'm using the http procedures to have my application download zip files from my website. Although the download process works OK, it adds a few bytes to the file during the download, so a 46k file becomes 52k. I can still open the file...
1
1011
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 then the file opens up in the browser which I do not want. The files are either excel, word or txt.
6
2289
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 ever I try to download a file I get the following error Can't Find Server or DNS error Any ideas please ?
1
1599
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 World</TITLE> <ENTRY> <AUTHOR>Me</AUTHOR>
0
1495
by: tanyali | last post by:
using php5, I download files : ******** downloadfile.php $fileContent = @mysql_result($result1,$i,"gdata"); $ourFileName = "$gribname"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fwrite($ourFileHandle, $fileContent); fflush($ourFileHandle); ...
2
1348
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. *** Sent via Developersdex http://www.developersdex.com ***
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10408
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7673
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6895
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5561
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.