I am sending a large file (3gb) through ftp in c# and I'm geting an error while reading the file in the Source Stream when I am doing this :
StreamReader sourceStream = new StreamReader(@"C:\xxx\xxxx\xxx");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
The error :
An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
The entire code :
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xxx.xxx.xxx.xxx/file.iso");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("user", "mdp");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(@"C:\xxx\xxx\xxx\xxxxxxxxx.iso");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();