即将到来的异常远程服务器返回错误:150打开文件下载的数据通道

问题描述 投票:0回答:1

我已经写了从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;
    }
c# asp.net ftp ftp-client ftpwebrequest
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.