I was uploading my file using below code,it works fine but some time it throws this error"The underlying connection was closed: The server committed a protocol violation" and stop the process ,when i run it again it upload file with out any issue.
One thing i noticed,if i run this process to upload multiple files then i get this error sometime,if i do less than 5 files then it works fine,any idea where and what i have to look in to it.
I was searchin google nothing found solid solution for this,even one of the msdn blog saying its a bug in FTPwebrequest but not sure.
Thanks in Advance
FileInfo fileInf = new FileInfo(filename);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create
(new Uri(path + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(user, pwd);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.Timeout = -1;
reqFTP.UsePassive = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 4096;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
try
{
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
strm.Close();
fs.Close();
}