var ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(strFTPIP + strFile);
ftpWebRequest.KeepAlive = false;
ftpWebRequest.UseBinary = true;
ftpWebRequest.Credentials = new NetworkCredential(strFTPuserName, strFTPPassword);
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
using (var inputStream = File.OpenRead(filepath))
using (var outputStream = ftpWebRequest.GetRequestStream())
{
var buffer = new byte[4096];
int totalReadBytesCount = 0;
int readBytesCount;
while ((readBytesCount = inputStream.Read(buffer, 0, buffer.Length)) > 0)
{
outputStream.Write(buffer, 0, readBytesCount);
totalReadBytesCount += readBytesCount;
var progress = totalReadBytesCount * 100.0 / inputStream.Length;
}
}
ftpWebRequest.Abort();