简体   繁体   English

使用Filezilla服务器在C#中通过SSL通过ftp发送文件

[英]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#. 我正在尝试使用C#中的ftps将文件发送到ftp服务器。 I am using filezilla server to test locally. 我正在使用filezilla服务器在本地进行测试。 I already tried using just regular ftp (without EnableSsl) and it works fine. 我已经尝试过仅使用常规ftp(不使用EnableSsl),并且工作正常。 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. 在filezilla上,我在设置中使用了它们的“生成证书”并将其保存到桌面。 So what is the file I need to use to create certificate from? 那么我需要用来创建证书的文件是什么? Is it the one filezilla generated? 它是一个生成的filezilla吗? If so, its a .crt file, so I wasn't able to use the CreateFromCertFile() method.. 如果是这样,则它是一个.crt文件,因此我无法使用CreateFromCertFile()方法。

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 我有这样的ftp请求

 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; };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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