在FTPWebrequest中启用SSL后无法连接FileZilla [英] couldn't able to connect FileZilla after enable SSL in FTPWebrequest

查看:453
本文介绍了在FTPWebrequest中启用SSL后无法连接FileZilla的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在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.

引自 http://ftps.codeplex.com/

.Net Framework提供的System.Net.FTPWebRequest类非常适合简单的任务(例如下载或上传文件或获取目录列表),并且还通过EnableSsl属性支持SSL请参阅:

The System.Net.FTPWebRequest class provided by the .Net Framework, is perfect for simple tasks (e.g. downloading or uploading a file or getting a directory list) and supports also SSL via the EnableSsl property See: http://blogs.msdn.com/adarshk/archive/2005/04/22/410925.aspx . So why a new class for that?

要点是,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆