
[英]FTP Error The remote server returned an error: 150 Opening data channel for file download
[英]FTP Server generates "Error: 150 Opening data channel for file download"
我编写了将文件从 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;
}
我今天在安装 kb 4519976 后遇到了这个问题。卸载这个 KB 解决了这个问题。 您能否检查这是否也是您的情况的解决方案。
上下文是一个 ftps tls 1.2 ECHDE 连接,它在启动额外连接的阶段失败。
除了@ user5783581提到的kb4519976(它是Windows 7、2008R2更新)之外,以下更新还存在该问题:
Windows 10,2016年:
Windows 8.1、2012:
如果有人找到了解决方案,那么共享它会很棒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.