简体   繁体   English

FtpWebRequest TLS 连接是否需要客户端证书?

[英]Does FtpWebRequest TLS connection need a client certificate?

I'm trying to create a FTPRequest using FtpWebRequest to send a report file to my server.我正在尝试使用FtpWebRequest创建一个FTPRequest以将报告文件发送到我的服务器。 But i don't understand about SSL/TLS connection.但我不了解 SSL/TLS 连接。

The server I'm using accepts TLS connections.我使用的服务器接受 TLS 连接。 So, is just setting EnableSsl = true enough?那么,仅仅设置EnableSsl = true足够了吗? Or do I need a client certificate?或者我需要客户证书?

If I just set to EnableSsl to true the connection is accepted and the file sent.如果我只是将EnableSsl设置为true则连接被接受并发送文件。

ftpRequest = (FtpWebRequest)WebRequest.Create(url);
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = false;
ftpRequest.Proxy = null;
ftpRequest.Credentials = new NetworkCredential(username, password);

If I want TLS/SSL:如果我想要 TLS/SSL:

ftpRequest.EnableSsl = true;
X509Certificate cert = X509Certificate.CreateFromCertFile(filePath);

X509CertificateCollection certCollection = new X509CertificateCollection { cert };

ftpRequest.ClientCertificates = certCollection;

If I set the certificate and try to connect, the server does not respond and don't give me any exception.如果我设置证书并尝试连接,服务器不会响应并且不会给我任何异常。
Do I really need a certificate?我真的需要证书吗? I don't know if the certificate is having a difference on connection or not.我不知道证书是否在连接上有差异。 What's the purpose of certificate?证书的目的是什么?

Thanks谢谢

A client certificate is a way of an authentication (as an alternative or a complement to a password).客户端证书是一种身份验证方式(作为密码的替代或补充)。 You need it only, if your FTPS server requires an authentication with a client certificate.仅当您的 FTPS 服务器需要使用客户端证书进行身份验证时才需要它。 It's similar to authentication with a private key in SSH.它类似于使用 SSH 中的私钥进行身份验证。

In my experience, client certificates are used very rarely.根据我的经验,很少使用客户端证书。 Had you needed it, you would know.如果你需要它,你就会知道。 And you would typically not have a password (though it's possible, while even rarer, that your need both a password and a client certificate to authenticate).而且您通常没有密码(尽管有可能,甚至更罕见的是,您需要密码和客户端证书来进行身份验证)。

So usually, to use FTPS (FTP over TLS/SSL), all you need is:通常,要使用 FTPS(基于 TLS/SSL 的 FTP),您只需要:

ftpRequest.EnableSsl = true;

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

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