Ive been having a problem downloading files through a proxy server. it worked fine while i was downloading small test files (zip files to be exact < 5kb) but when i use actual files, they are always corrupt on the client side, but when you open the zip file there are never more than 2 files present and they are corrupt as well. any help would be greatly appreciated.
Thanks,
here is a before and after screen shot of the zip files, if that helps, and the following is a code snippit.
public void BeginDownload(){
WebProxy proxy = new WebProxy(ServPath, true);
proxy.Credentials = new NetworkCredential(UserName, Pass);
WebRequest request = WebRequest.Create(ServPath + FileName);
request.Proxy = proxy; // Send the 'HttpWebRequest' and wait for response. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
FileStream writeStream = new FileStream(DownloadPath + FileName, FileMode.Create, FileAccess.Write);
ReadWriteStream(stream, writeStream, response
.ContentLength);response
.Close();}
private void ReadWriteStream(Stream readStream, Stream writeStream, long lLength){ int Length = Convert.ToInt32(lLength);
Byte[] buffer = new Byte[Length + (100 - Length%100) + 5];
int numBytesToRead = Length;
int numBytesRead = 0; while (numBytesToRead > 0){
int n;
n = readStream.Read(buffer, numBytesRead, numBytesToRead);
WriteStream.Write(buffer, numBytesRead, numBytesToRead);
numBytesRead += n;
numBytesToRead -= n;
}
readStream.Close();
writeStream.Close();
}
rickPosted Jun 8, 2006, 12:13 PM
Byte[] buffer = new Byte[lLength + 5];// + (100 - Length%100) + 5];
int numBytesRead = 0;
while (Length > numBytesRead)
{
int n;
n = readStream.Read(buffer, numBytesRead, Length-numBytesRead);
writeStream.Write(buffer, numBytesRead, n);
numBytesRead += n;
tslDLProgressLabel.Text = numBytesRead.ToString() + " bytes / " + Length.ToString() + " bytes";
tsDLProgress.Value = numBytesRead;
tsDownload.Refresh();
}
Thanks for your help...or lack there of!
;) haha jk
rickPosted Jun 6, 2006, 11:25 AM
original file size -> downloaded file size
11kb -> 18kb
66kb -> 128kb
ive noticed that these numbers are (double the original - 4kb). im confused because there is less within the actual zip file but the file sizes are larger?? :S
hope this helps with a resolution. Thanks again,
Mahesh ChandPosted Jun 2, 2006, 12:51 PM