0

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??

Lahib
  • 1,305
  • 5
  • 34
  • 62

1 Answers1

1

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.

  • Thanks for the help. But there is no other way in avoiding to run alle these line of code more than once ? – Lahib Sep 27 '12 at 07:36
  • Why don`t you create some method so you can call it when you need? In that case you`ll have less lines. P.S. Anyway you should read this when you have time. I think it`s far more convenient way to work with ftp: http://winscp.net/eng/docs/library – Nikola Crnomarkovic Sep 27 '12 at 07:48
  • i appreciate the help. i will do some reading then. thanks again! – Lahib Sep 27 '12 at 07:55