473,386 Members | 1,766 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,386 software developers and data experts.

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 SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"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 1834
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*********************@75g2000cwc.googlegrou ps.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 SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"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*********************@75g2000cwc.googlegrou ps.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 SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"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*********************@75g2000cwc.googlegrou ps.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 SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"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.ConnectionLimit 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*********************@75g2000cwc.googlegrou ps.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 SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"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.ConnectionLimit 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*********************@75g2000cwc.googlegrou ps.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 SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"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
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...
1
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...
0
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...
1
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...
3
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...
0
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) {...
6
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...
5
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...
39
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.