问题描述
我试图在ftpwebrequest中使用SSL,如下所示
I was trying to use SSL in ftpwebrequest like below
FileStream outputStream = new FileStream(fileName, FileMode.Append);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpserverIp + "/" + file));
reqFTP.EnableSsl = true;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.KeepAlive = false;
reqFTP.Timeout = -1;
reqFTP.UsePassive = true;
reqFTP.Credentials = new NetworkCredential("sh", "SE");
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
// reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
int bufferSize = 4096;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
Console.WriteLine("Connected: Downloading File");
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
//Console.WriteLine(readCount.ToString());
}
ftpStream.Close();
outputStream.Close();
response.Close();
我得到以下异常:
根据验证过程,远程证书无效.
The remote certificate is invalid according to the validation procedure.
基于我的Google,删除证书中的私钥部分并立即开始处理
Based on my google remove the private key part in the certificate and start processing now it throws
431无法初始化ssl连接
我尝试过谷歌搜索,但到目前为止没有结果,任何想法的人.
I tried googling but no result so far,any idea guys.
正在尝试连接FileZilla.
Am trying to connect FileZilla.
推荐答案
答案很简单,即FtpWebRequest甚至都不支持FTPS足够好.
The answer is simple that FtpWebRequest does not even support FTPS good enough.
要点是,FTP中的SSL支持不仅仅是一个开/关开关(如HTTP/HTTPS). FTP需要两个单独的连接:一个用于命令(控制连接),另一个用于数据(数据连接),用于下载,上传和目录列表.FTPWebRequest.EnableSsl只需在两者上强制使用SSL.问题在于这并不总是合适的.
The point is that SSL support in FTP is more that an on/off switch (as in HTTP/HTTPS). FTP requires two separate connections: one for the commands (the control connection) and one for the data (the data connection), for downloads, uploads and directory listings.FTPWebRequest.EnableSsl simply forces the use of SSL on both of them. The problem is that this is not always suitable.
Microsoft仅在为Windows Server 2008及更高版本提供FTP 7.5时才开始在服务器端支持FTPS.到目前为止,他们甚至在Internet Explorer和Windows Explorer中都不支持FTPS.难怪.NET Framework BCL缺少FTPS支持.
Microsoft only starts to support FTPS on server side when they provide FTP 7.5 for Windows Server 2008 and above. Up to now, they don't even support FTPS in Internet Explorer nor Windows Explorer. No wonder .NET Framework BCL lacks FTPS support.
这篇关于在FTPWebrequest中启用SSL后无法连接FileZilla的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!