我正在使用我自己的同步器为库FTPLibrary下载 .zip执行调试时,我在此代码中发现错误
数据:Visual Studio 2012。Windows 窗体应用程序 - C#
try
{
//Give Message of Command
NewMessageEventArgs e = new NewMessageEventArgs("COMMAND", "Download File", "RETR");
OnNewMessageReceived(this, e);
byte[] buffer = new byte[2048];
int read = 0;
Int64 TotalBytesRead = 0;
Int64 FileSize = this.GetFileSize(sourceFilename);
DownloadCanceled = false;
do
{
if (DownloadCanceled)
{
NewMessageEventArgs CancelMessage = new NewMessageEventArgs("RESPONSE", "Download Canceled.", "CANCEL");
DownloadCanceled = false;
OnNewMessageReceived(this, CancelMessage);
return false;
}
read = DownloadResponseStream.Read(buffer, 0, buffer.Length);
DownloadFileStream.Write(buffer, 0, read);
TotalBytesRead += read;
//Declare Event
DownloadProgressChangedArgs DownloadProgress = new DownloadProgressChangedArgs(TotalBytesRead, FileSize);
//Progress changed, Raise the event.
OnDownloadProgressChanged(this, DownloadProgress);
System.Windows.Forms.Application.DoEvents();
} while (!(read == 0));
//Get Message and Raise Event
NewMessageEventArgs NewMessageArgs = new NewMessageEventArgs("RESPONSE", DownloadResponse.StatusDescription, DownloadResponse.StatusCode.ToString());
OnNewMessageReceived(this, NewMessageArgs);
//Declare Event
DownloadCompletedArgs Args = new DownloadCompletedArgs("Successful", true);
//Raise Event
OnDownloadCompleted(this, Args);
DownloadResponseStream.Close();
DownloadFileStream.Flush();
DownloadFileStream.Close();
DownloadFileStream = null;
DownloadResponseStream = null;
}
catch (Exception ex)
{
//catch error and delete file only partially downloaded
DownloadFileStream.Close();
//delete target file as it's incomplete
targetFI.Delete();
//Decalre Event for Error
DownloadCompletedArgs DownloadCompleted = new DownloadCompletedArgs("Error: " + ex.Message, false);
//Raise Event
OnDownloadCompleted(this, DownloadCompleted);
}
}
更多信息,请参见类 FTPLibrary。第 391 行出错。
El error está en :
读取 = DownloadResponseStream.Read(buffer, 0, buffer.Length);
该程序是一个同步器,首先下载一个100 kb的.zip,然后下载150 MB,我们得到以下错误
西班牙语:WebException: Se ha terminado la conexión: Error inesperado de recepción 英语:底层连接已关闭:意外错误
这会导致程序下载 150 MB 然后跳转标记和错误,导致您无法使用该文件进行以后的操作,程序结束。我认为问题出在缓冲区中,而不是如何解决。下载文件时,我使用 Windows 2003 连接到 FTP 服务器。谢谢你,我希望你能帮助我。