// I have this code below that does fine for uploading file from a server to another, but I am concerned if the client have a large file to FTP, I am looking for some code to implement the idea of buffering/streaming chunks of the file instead of FTPing the file in one shot, the line of code that I am thinking to change is "requestStream.Write(fileContents, 0, fileContents.Length);" This is where I need to loop through and send the file in chunks to FTP server, any ideas on how to do that?
FtpWebRequest request = null;
StreamReader sourceStream = null;
Stream requestStream = null;
FtpWebResponse response = null;
// Get the object used to communicate with the server.
request = (FtpWebRequest)WebRequest.Create(@ftpServer + tmpFilename);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = true;
request.EnableSsl = true;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential(ftpUser, connectionStringToFTP);
// Copy the contents of the file to the request stream.
sourceStream = new StreamReader(@fromSource + tmpFilename);
byte fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
request.ContentLength = fileContents.Length;
requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
if (requestStream != null)
response = (FtpWebResponse)request.GetResponse();
bool ftpSuccessful = false;
ftpSuccessful = true;
//catch something required to be captured....etc.
//close/dispose/flush streams here