I am using C# to download - via FTP - some files and save them locally (on a network). The files are zipped. The class I have developed so far does a fine job with the smaller files, but I get a "Exception of type 'System.OutOfMemoryExcepti
on' was thrown." error with the larger files. By "smaller" I mean < 50MB, by "larger" I mean 350MB or so.
Here is the download method of my FTP class:
// Download a file from the FTP server to the destination
public void Download(string file, string destination)
FtpWebRequest request = (FtpWebRequest)WebRequest.
moteHost + file);
request.Method = WebRequestMethods.Ftp.DownloadFile
request.Credentials = new NetworkCredential(_remoteU
FtpWebResponse response = (FtpWebResponse)request.Ge
Stream responseStream = response.GetResponseStream
StreamReader reader = new StreamReader(responseStrea
StreamWriter writer = new StreamWriter(destination);
and I call it like this:
I call this in a loop, and it will copy files until it hits a larger one, then I get the exception at the line:
The files that it does copy are fine.
I know I need to somehow stream the file transfer - it must be trying to hold the whole thing in memory - but I just started using C# so I don't really know how to go about it.
Any help is much appreciated.
**NOTE** Let me amend this - I further checked the zip files that were - supposedly - copied without an error and found that they are NOT valid zip files. They just have the correct name and the zip extension. Also, they are all a little larger than the originals (about 2/3 larger). I looked at them in a hex viewer and I can't tell what the difference is, but it's obviously significant. So I guess I have 2 problems...