473,563 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Slow Downloading

Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFil e(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullO rEmpty(filePath ) || stream == null)
// return false;
// System.IO.Strea m gzStream = stream; //= new
System.IO.Strea m()//(stream,
System.IO.Compr ession.Compress ionMode.Decompr ess);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(fileP ath, FileMode.Create ,
FileAccess.Writ e, FileShare.Read) ;
while ((bytesRead = stream.Read(inB uffer, 0,
inBuffer.Length )) 0)
{
fs.Write(inBuff er, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy .HandleExceptio n(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.Kee pAlive = true;
webRequest1.Coo kieContainer = cookies;
webRequest1.Acc ept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5";
webRequest1.Hea ders.Set("Accep t-Language",
"en-us,en;q=0.5");
webRequest1.Hea ders.Set("Accep t-Encoding", "gzip,deflate") ;
webRequest1.Hea ders.Set("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");
webRequest1.Hea ders.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.Get Response();
Stream ReceiveStream1 = myResponse1.Get ResponseStream( );
SaveStreamToFil e(@"C:\file.csv ", ReceiveStream1) ;

the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)

please suggest me , how to solve this problem .
Thanks , Rony

Aug 17 '06 #1
5 1848
Havent read the code but a quick thought, the server that is hosting the
file you are downloading, whats its upstream bandwidth?

"rony_16" <ro***********@ gmail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFil e(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullO rEmpty(filePath ) || stream == null)
// return false;
// System.IO.Strea m gzStream = stream; //= new
System.IO.Strea m()//(stream,
System.IO.Compr ession.Compress ionMode.Decompr ess);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(fileP ath, FileMode.Create ,
FileAccess.Writ e, FileShare.Read) ;
while ((bytesRead = stream.Read(inB uffer, 0,
inBuffer.Length )) 0)
{
fs.Write(inBuff er, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy .HandleExceptio n(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.Kee pAlive = true;
webRequest1.Coo kieContainer = cookies;
webRequest1.Acc ept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5";
webRequest1.Hea ders.Set("Accep t-Language",
"en-us,en;q=0.5");
webRequest1.Hea ders.Set("Accep t-Encoding", "gzip,deflate") ;
webRequest1.Hea ders.Set("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");
webRequest1.Hea ders.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.Get Response();
Stream ReceiveStream1 = myResponse1.Get ResponseStream( );
SaveStreamToFil e(@"C:\file.csv ", ReceiveStream1) ;

the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)

please suggest me , how to solve this problem .
Thanks , Rony

Aug 17 '06 #2
Hi,

Where is the server hosted?
What performance do you get if you try to download this same file frmo the
browser.

Are you getting any exception?
Is the file compressed when you download it? I see you setup several headers
in the request, what if you do not do it?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"rony_16" <ro***********@ gmail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFil e(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullO rEmpty(filePath ) || stream == null)
// return false;
// System.IO.Strea m gzStream = stream; //= new
System.IO.Strea m()//(stream,
System.IO.Compr ession.Compress ionMode.Decompr ess);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(fileP ath, FileMode.Create ,
FileAccess.Writ e, FileShare.Read) ;
while ((bytesRead = stream.Read(inB uffer, 0,
inBuffer.Length )) 0)
{
fs.Write(inBuff er, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy .HandleExceptio n(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.Kee pAlive = true;
webRequest1.Coo kieContainer = cookies;
webRequest1.Acc ept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5";
webRequest1.Hea ders.Set("Accep t-Language",
"en-us,en;q=0.5");
webRequest1.Hea ders.Set("Accep t-Encoding", "gzip,deflate") ;
webRequest1.Hea ders.Set("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");
webRequest1.Hea ders.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.Get Response();
Stream ReceiveStream1 = myResponse1.Get ResponseStream( );
SaveStreamToFil e(@"C:\file.csv ", ReceiveStream1) ;

the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)

please suggest me , how to solve this problem .
Thanks , Rony

Aug 17 '06 #3
hi,
when i download this file through browser, it being downloaded very
fast .
and the server is very fast .
what i do know that this file protected with SSL .

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

Where is the server hosted?
What performance do you get if you try to download this same file frmo the
browser.

Are you getting any exception?
Is the file compressed when you download it? I see you setup several headers
in the request, what if you do not do it?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"rony_16" <ro***********@ gmail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFil e(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullO rEmpty(filePath ) || stream == null)
// return false;
// System.IO.Strea m gzStream = stream; //= new
System.IO.Strea m()//(stream,
System.IO.Compr ession.Compress ionMode.Decompr ess);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(fileP ath, FileMode.Create ,
FileAccess.Writ e, FileShare.Read) ;
while ((bytesRead = stream.Read(inB uffer, 0,
inBuffer.Length )) 0)
{
fs.Write(inBuff er, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy .HandleExceptio n(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.Kee pAlive = true;
webRequest1.Coo kieContainer = cookies;
webRequest1.Acc ept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5";
webRequest1.Hea ders.Set("Accep t-Language",
"en-us,en;q=0.5");
webRequest1.Hea ders.Set("Accep t-Encoding", "gzip,deflate") ;
webRequest1.Hea ders.Set("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");
webRequest1.Hea ders.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.Get Response();
Stream ReceiveStream1 = myResponse1.Get ResponseStream( );
SaveStreamToFil e(@"C:\file.csv ", ReceiveStream1) ;

the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)

please suggest me , how to solve this problem .
Thanks , Rony
Aug 18 '06 #4
Your code is pretty much correct. You're having keep alive turned on
though, and I don't see disposal code on your response. The framework
internals live by the protocol specs for https that say that you can
only have 2 current connections to the same domain over https at the
same time. If you're running this code in succession, or threading it,
you will have problems with one download preventing the other from
downloading. This is the only thing I can think of which would cause a
slow download. You can override this behavior by setting the
ServicePoint.Co nnectionLimit to a higher number, like say 50 or so. I
would also suggest making absolutely sure you have using blocks on
every single declared variable that you can in there as I've seen a lot
of issues just coming from people not realizing that a stream was still
open. You can always packet sniff the download and see what's actually
going on between you and the server under the covers.

Bruce Dunwiddie
http://www.csvreader.com

rony_16 wrote:
hi,
when i download this file through browser, it being downloaded very
fast .
and the server is very fast .
what i do know that this file protected with SSL .

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

Where is the server hosted?
What performance do you get if you try to download this same file frmo the
browser.

Are you getting any exception?
Is the file compressed when you download it? I see you setup several headers
in the request, what if you do not do it?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"rony_16" <ro***********@ gmail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFil e(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullO rEmpty(filePath ) || stream == null)
// return false;
// System.IO.Strea m gzStream = stream; //= new
System.IO.Strea m()//(stream,
System.IO.Compr ession.Compress ionMode.Decompr ess);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(fileP ath, FileMode.Create ,
FileAccess.Writ e, FileShare.Read) ;
while ((bytesRead = stream.Read(inB uffer, 0,
inBuffer.Length )) 0)
{
fs.Write(inBuff er, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy .HandleExceptio n(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.Kee pAlive = true;
webRequest1.Coo kieContainer = cookies;
webRequest1.Acc ept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5";
webRequest1.Hea ders.Set("Accep t-Language",
"en-us,en;q=0.5");
webRequest1.Hea ders.Set("Accep t-Encoding", "gzip,deflate") ;
webRequest1.Hea ders.Set("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");
webRequest1.Hea ders.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.Get Response();
Stream ReceiveStream1 = myResponse1.Get ResponseStream( );
SaveStreamToFil e(@"C:\file.csv ", ReceiveStream1) ;
>
the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)
>
please suggest me , how to solve this problem .
Thanks , Rony
>
Aug 18 '06 #5
thanks , i will try it .

shriop wrote:
Your code is pretty much correct. You're having keep alive turned on
though, and I don't see disposal code on your response. The framework
internals live by the protocol specs for https that say that you can
only have 2 current connections to the same domain over https at the
same time. If you're running this code in succession, or threading it,
you will have problems with one download preventing the other from
downloading. This is the only thing I can think of which would cause a
slow download. You can override this behavior by setting the
ServicePoint.Co nnectionLimit to a higher number, like say 50 or so. I
would also suggest making absolutely sure you have using blocks on
every single declared variable that you can in there as I've seen a lot
of issues just coming from people not realizing that a stream was still
open. You can always packet sniff the download and see what's actually
going on between you and the server under the covers.

Bruce Dunwiddie
http://www.csvreader.com

rony_16 wrote:
hi,
when i download this file through browser, it being downloaded very
fast .
and the server is very fast .
what i do know that this file protected with SSL .

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,
>
Where is the server hosted?
What performance do you get if you try to download this same file frmo the
browser.
>
Are you getting any exception?
Is the file compressed when you download it? I see you setup several headers
in the request, what if you do not do it?
>
>
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
>
>
>
"rony_16" <ro***********@ gmail.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFil e(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullO rEmpty(filePath ) || stream == null)
// return false;
// System.IO.Strea m gzStream = stream; //= new
System.IO.Strea m()//(stream,
System.IO.Compr ession.Compress ionMode.Decompr ess);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(fileP ath, FileMode.Create ,
FileAccess.Writ e, FileShare.Read) ;
while ((bytesRead = stream.Read(inB uffer, 0,
inBuffer.Length )) 0)
{
fs.Write(inBuff er, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy .HandleExceptio n(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.Kee pAlive = true;
webRequest1.Coo kieContainer = cookies;
webRequest1.Acc ept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5";
webRequest1.Hea ders.Set("Accep t-Language",
"en-us,en;q=0.5");
webRequest1.Hea ders.Set("Accep t-Encoding", "gzip,deflate") ;
webRequest1.Hea ders.Set("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");
webRequest1.Hea ders.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.Get Response();
Stream ReceiveStream1 = myResponse1.Get ResponseStream( );
SaveStreamToFil e(@"C:\file.csv ", ReceiveStream1) ;

the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)

please suggest me , how to solve this problem .
Thanks , Rony
Aug 20 '06 #6

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

Similar topics

5
618
by: No_Excuses | last post by:
All, I am interested in reading the text of a web page and parsing it. After searching on this newgroup I decided to use the following: ******************************* START OF CODE ************************ String sTemp = "http://cgi3.igl.net/cgi-bin/ladder/teamsql/team_view.cgi?ladd=teamknights&num=238&showall=1"; WebRequest...
1
2057
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the...
0
1625
by: just.starting | last post by:
I am having problem while downloading files from an apache server2.0.53 with php4.3.10.While downloading some files it generally stops after downloading some specific amount and then stops downloading with the error message: "the source file could not be read". And the error is not dependent on the size of the file, as I can download a file of...
1
1258
by: tsbgrp | last post by:
hi there i have a problem related to slow downloading speed.the situation is i have about 60 PC's in a domain.when i ping ISP Gateway from a LAN PC i get the replies...22, 25,35, 400, 50ms an some times 22, 40, 220, 150, 30, 100ms...I get lot of variations and when i ping from server PC by disconnecting LAN then i get theese replies ......
3
2205
by: Mantorok | last post by:
Hi all I'm writing a newsgroup reader in C# and I've found the TcpClient to be extremely slow, when downloading a list of newsgroups for example it runs at about 8Kb/sec over a 2Mb/sec connection. Any ideas? Is this just the way it is?? Thanks Kev
0
864
by: rony_16 | last post by:
Hi, I have a problem downloading a file . after i connect to the website and get the stream , i treing to write the file on the HD. public void SaveStreamToFile(string filePath, Stream stream) { // If not all data was provided return false; //if (string.IsNullOrEmpty(filePath) || stream == null) // return false; // System.IO.Stream...
6
1918
by: bg_ie | last post by:
Hi, My company's backend is located at a location with a long address, something like - //our_servers/server_number_one/our_department/our_devision/ our_results/our_databases/backend.be I have tested the very same backend on another server with a sort path location at it works fine, but at the location above it is extremely
5
1299
by: Geoff Cox | last post by:
Hello, I have a page for which downloading into the browser is very slow. I have tried using YSlow and firebug but is there any way in which I can actually see which files are taking a long time to be downloaded? Cheers Geoff
39
2826
by: cm_gui | last post by:
Python is slow. Almost all of the web applications written in Python are slow. Zope/Plone is slow, sloow, so very slooow. Even Google Apps is not faster. Neither is Youtube. Facebook and Wikipedia (Mediawiki), written in PHP, are so much faster than Python. Okay, they probably use caching or some code compilation -- but Google Apps...
0
7664
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
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...
1
5484
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.