我想了解SSL如何工作。在我的願望,使一個小的FTP客戶端支持SSL我碰到的一些問題:原始FTP SSL與C#
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(文本); 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,直到AUTH SSL發送到它。所以我的問題是,我將如何去做這個「混合」連接,所以我可以做一個SSL連接到服務器?
任何幫助,非常感謝!