Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# FtpWebRequest TLS连接是否需要客户端证书?_C#_Ftp_Client Certificates_Ftpwebrequest_Ftps - Fatal编程技术网

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

C# FtpWebRequest TLS连接是否需要客户端证书?,c#,ftp,client-certificates,ftpwebrequest,ftps,C#,Ftp,Client Certificates,Ftpwebrequest,Ftps,我正在尝试使用FtpWebRequest创建一个FTPRequest来向我的服务器发送报告文件。但我不了解SSL/TLS连接 我使用的服务器接受TLS连接。那么,仅仅设置EnableSsl=true就足够了吗?或者我需要客户端证书吗 如果我只是将EnableSsl设置为true,则连接被接受,文件被发送 ftpRequest = (FtpWebRequest)WebRequest.Create(url); ftpRequest.UseBinary = true; ftpRequest.UsePa

我正在尝试使用
FtpWebRequest
创建一个
FTPRequest
来向我的服务器发送报告文件。但我不了解SSL/TLS连接

我使用的服务器接受TLS连接。那么,仅仅设置
EnableSsl=true
就足够了吗?或者我需要客户端证书吗

如果我只是将
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);
如果我想要TLS/SSL:

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

X509CertificateCollection certCollection = new X509CertificateCollection { cert };

ftpRequest.ClientCertificates = certCollection;
如果我设置证书并尝试连接,服务器不会响应,也不会给我任何异常。
我真的需要证书吗?我不知道证书在连接上是否有差异。证书的目的是什么


谢谢

客户端证书是身份验证的一种方式(作为密码的替代或补充)。仅当FTPS服务器需要使用客户端证书进行身份验证时,才需要它。这类似于SSH中使用私钥进行身份验证

根据我的经验,很少使用客户机证书。如果你需要它,你会知道的。而且您通常不需要密码(尽管您可能需要密码和客户端证书来进行身份验证,但这种情况更为罕见)

因此,通常,要使用FTPS(通过TLS/SSL的FTP),您只需要:

ftpRequest.EnableSsl = true;

我感谢你的帮助。谢谢