简体   繁体   中英

sending file using ftp over ssl in C#, with filezilla server

I'm trying to send a file to a ftp server using ftps in C#. I am using filezilla server to test locally. I already tried using just regular ftp (without EnableSsl) and it works fine. I've already looked around and I'm trying to set up the certificates, but I can't get it to work. I keep getting error: the remote certificate is invalid according to the validation procedure. On filezilla, I used their "generate certificate" in the settings and saved it to desktop. So what is the file I need to use to create certificate from? Is it the one filezilla generated? If so, its a .crt file, so I wasn't able to use the CreateFromCertFile() method..

This is where I add the certificate

X509Certificate cert = X509Certificate.CreateFromCertFile(pathtofile);
  X509CertificateCollection certCollection = new X509CertificateCollection();
  certCollection.Add(cert);

  request.ClientCertificates.Add(cert);

I have the ftp request like this

 var request = (FtpWebRequest) WebRequest.Create(fullPath);
      request.UseBinary = true;
      request.Method = WebRequestMethods.Ftp.UploadFile;
      request.EnableSsl = true;
 request.KeepAlive = false;
      request.Credentials = new NetworkCredential(username, password);
      request.UsePassive = true;

Thanks in advance

如果您的证书是自签名的,则需要告诉ServicePointManager接受它。

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM