I am trying to upload some txt files to ftp site as below.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("FTP PATH");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new System.Net.NetworkCredential(username, password);
request.EnableSsl = true;
X509Certificate cert = X509Certificate.CreateFromCertFile(certificate path);
X509CertificateCollection certCollection = new X509CertificateCollection();
certCollection.Add(cert);
request.ClientCertificates = certCollection;
StreamReader sourceStream = new StreamReader("localfile path to upload");
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.StatusDescription);
writelog("response:.."+response.StatusDescription);
response.Close();
and its uploading the files some time and sometime iam encoutering with an error. please check below logs
Successful Log
4/12/2017 10:43:16 AM:Uploading file to ftp
4/12/2017 10:43:21 AM:response:..226 Closing data connection, Binary transfer complete.
4/12/2017 10:43:21 AM:end Uploading file to ftp
Failure Log
4/12/2017 10:43:22 AM:Uploading file to ftp
4/12/2017 10:43:23 AM : System : The remote server returned an error: 125 Data connection already open; transfer starting.
I am not able to identify the issue please help