Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
原始FTP SSL与C#_C#_Ssl_Ftp_Authentication_Sslstream - Fatal编程技术网

原始FTP SSL与C#

原始FTP SSL与C#,c#,ssl,ftp,authentication,sslstream,C#,Ssl,Ftp,Authentication,Sslstream,我试图了解SSL是如何工作的。我希望制作一个支持SSL的小型FTP客户端,但遇到了一些问题: TcpClient FtpConnection = new TcpClient(FtpServer, FtpPort); NetworkStream FtpStream = FtpConnection.GetStream(); StreamReader FtpReader = new StreamReader(FtpStream); FtpWriter = new StreamWriter(IrcStr

我试图了解SSL是如何工作的。我希望制作一个支持SSL的小型FTP客户端,但遇到了一些问题:

TcpClient FtpConnection = new TcpClient(FtpServer, FtpPort);
NetworkStream FtpStream = FtpConnection.GetStream();
StreamReader FtpReader = new StreamReader(FtpStream);
FtpWriter = new StreamWriter(IrcStream);
send_cmd("AUTH SSL");
send_cmd只是一个FtpWriter.WriteLine(text);FtpWriter.Flush();功能

我的“问题”是:首先我需要与FTP建立一个(非ssl)连接,然后告诉它进行ssl连接(AUTH ssl),然后我想我需要建立一个新的连接,比如:

TcpClient client = new TcpClient(FtpServer, FtpPort);
SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
try
{
    sslStream.AuthenticateAsClient("foobar");
}
catch (AuthenticationException e)
{
    MessageBox.Show("Authentication failed - closing the connection.");
    client.Close();
    return;
}
摘自msdn。 由于意外的数据包格式(我在谷歌上搜索过,但所有人都说这是因为作者连接到了错误的端口),我一直在等待握手失败,我认为:在向其发送身份验证ssl之前,连接不是ssl。因此,我的问题是,我将如何使这成为一个“混合”连接,以便能够与服务器建立SSL连接

非常感谢您的帮助


这个项目包含了你需要的每一部分。

使用这样的库与我想要的正好相反。由于我在搜索网页时发现的点击率太低,我将发布我的发现: 构建C#ftp客户端基本上是这样的:

TcpClient blabla = new TcpClient("some.host", 21);
NetworkStream blabla_stream = blabla.GetStream();
StreamReader unsecure_reader = new StreamReader(blabla_stream);
StreamWriter blabla_writer = new StreamWriter(blabla_stream);
blabla_writer.WriteLine("AUTH SSL");
string response = "";
while ((response = unsecure_reader.ReadLine()) != null)
{
   if (response.Substring(0,3) == "234")
   {
       SslStream ssl_connection = new SslStream(blabla.GetStream(), false, new RemoteCertificateValidationCallback(validate_certificate), null);
       ssl_connection.AuthenticateAsClient("");
       StreamReader ssl_stream = new StreamReader(ssl_connection);
       ftp_writer = new StreamWriter(ssl_connection);
   }
}
其中,validate_certificate是一个基于msdn的函数(您可以自己用谷歌搜索并修改它)

有关更多信息,请参阅RFC 4217和2228