Topic: FTP file transfer over SSL
im trying to upload file to one of the ftp servers I have but im getting exception while reaching the server server listening on port 990 i think the problem is with implicit/explicit settings can anyone suggest me how to do the ftp over SSL using implicit setting in .net 4.0?
The exception I am getting while calling the method GetRequestStream: The underlying connection was closed: The server committed a protocol violation.
Here is the code snippet:
FileInfo ExportFile = new FileInfo("C:\\ServiceXML.xml");
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftpserver" + "/FolderName/" + ExportFile.Name);
request.EnableSsl = true;
request.Credentials = new NetworkCredential("username", "password");
request.KeepAlive = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UseBinary = true;
request.ContentLength = ExportFile.Length;
request.UsePassive = true;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
try
{
int bufferLen = 4096;
byte[] buffer = new byte[4096];
int contentLen;
FileStream fsExport = ExportFile.OpenRead();
Stream ftpStream = request.GetRequestStream();
contentLen = fsExport.Read(buffer, 0, bufferLen);
while (contentLen != 0)
{
ftpStream.Write(buffer, 0, contentLen);
contentLen = fsExport.Read(buffer, 0, bufferLen);
}
fsExport.Close();
fsExport.Dispose();
ftpStream.Close();
ftpStream.Dispose();
}
catch (Exception ex)
{
//LogError(ex, "Error in FTP Request.");
}
Struggling with this issue for few days now..any help would be appreciated.. can anyone suggest me good example for FTP over SSL using implict settings in .net 4.0?