Lahib
Lahib

Reputation: 1365

Holding a Session when Connecting to FTP server C#

I'm have been working on an application witch uploads and downloads multiple files from a FTP server. My problem is that each and every time i want to download a single file, i need to connect to the FTP server, and check the certificates. This is the code it runs each time the upload or download method is used.

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp:...../inbox/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UsePassive = true;
reqFTP.UseBinary = true;
reqFTP.KeepAlive = true;
reqFTP.ServicePoint.ConnectionLimit = files.Length;
reqFTP.Credentials = new NetworkCredential("username", "password");
reqFTP.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = Certificate;

Is there a way to create the connection ONLY ONCE, and hold a Session with the required certificates??

Upvotes: 0

Views: 1055

Answers (1)

Nikola Crnomarkovic
Nikola Crnomarkovic

Reputation: 81

If you add this line to entry point of your app you will solve your problem with certificate:

System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

After that you just think about how to download/upload files and forget about checking certificate. Hope this helps.

Upvotes: 1

Related Questions