【问题标题】:FTP Server generates "Error: 150 Opening data channel for file download"FTP 服务器生成“错误:150 为文件下载打开数据通道”
【发布时间】:2020-01-11 03:13:33
【问题描述】:

我已经编写了将文件从 FTP 服务器传输到本地服务器的代码,并且在传输 2 或 3 个文件后抛出异常错误 远程服务器返回错误:150 打开文件下载数据通道

在 FileZila 中成功传输所有文件,但在 asp.net 应用程序中出现错误。

我做下面的代码

protected string TransferFile(string strPath, string strFtpPath, string strFtpUser, string strFtpPwd, string strSubClientFTPPath, string strSubClientFTPUser, string strSubClientFTPPwd, string strFileName, string strConvFileName, string strFileSize)
    {
        string strSuccess = "";
        FtpWebRequest reqFTP;
        try
        {

            Double Size = 0;
            string strLocalFileSize = "";
            if (File.Exists(strPath + strConvFileName))
            {
                Size = ((Math.Round(Convert.ToDouble(new FileInfo(strPath + strConvFileName).Length)) > 0 && Math.Round(Convert.ToDouble(new FileInfo(strPath + strConvFileName).Length)) < 1024) ? 1 : (Math.Round(Convert.ToDouble(new FileInfo(strPath + strConvFileName).Length) / 1024 + 0.0001)));
                strLocalFileSize = Size + "KB";
            }
            if (!File.Exists(strPath + strConvFileName) || strFileSize != strLocalFileSize)
            {
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpPath + strFileName.Replace("#", "%23")));
                System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
                reqFTP.EnableSsl = true;
                reqFTP.Timeout = Timeout.Infinite;
                reqFTP.KeepAlive = true;
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                //reqFTP.UseBinary = true;
                //reqFTP.UsePassive = false;
                reqFTP.Credentials = new NetworkCredential(strFtpUser, strFtpPwd);
                //   lblTransferredFile.Text = "Transferring " + strFileName + "  ......";
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                long cl = response.ContentLength;
                int bufferSize = 2048;
                int readCount;
                byte[] buffer = new byte[bufferSize];
                //  lblTransferredFile.Text = "Transferring " + strFileName + "  ......";
                readCount = ftpStream.Read(buffer, 0, bufferSize);
                //if (readCount > 0)
                //{
                FileStream outputStream = new FileStream(strPath +
                                                         strConvFileName, FileMode.Create);
                while (readCount > 0)
                {
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                }

                ftpStream.Close();
                outputStream.Close();
                response.Close();
                strSuccess = "";

            }
            else
            {
                strSuccess = "File Exists";
            }
        }
        catch (Exception ex)
        {
            strSuccess = ex.Message;
            ClientScript.RegisterStartupScript(this.GetType(), "strScript", "<script>alert('" + ex.Message.Trim().Replace("'", "") + "');</script>");
        }

        return strSuccess;
    }

【问题讨论】:

  • 在这一行抛出异常 FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();

标签: c# asp.net ftp ftp-client ftpwebrequest


【解决方案1】:

我今天在安装 kb 4519976 后遇到了这个问题。卸载这个 KB 解决了这个问题。您能否检查一下这是否也是您的解决方案。

上下文是一个 ftps tls 1.2 ECHDE 连接,在启动额外连接的阶段失败。

【讨论】:

  • 是的。它需要重新启动。
  • @user5783581 你能定义什么是 kb 4519976。
  • KB 4519976 是一个知识库编号。它描述了一个补丁。你可以在这里找到它support.microsoft.com/en-us/help/4519976/…
  • 这段代码在过去五年中运行良好,但从某个时候开始就无法运行了。还有一件事是我们使用线程处理进度条和文件与屏幕上的用户交互
  • 所以与我的问题类似的情况通过卸载最近的补丁解决了。是否安装了此补丁或预览版,您可以将其卸载吗?
猜你喜欢
  • 2020-02-06
  • 2016-09-02
  • 1970-01-01
  • 1970-01-01
  • 2014-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多