我正在使用以下代码从远程 ftp 服务器下载文件:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(userName, password);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
using (StreamWriter destination = new StreamWriter(destinationFile))
{
destination.Write(reader.ReadToEnd());
destination.Flush();
}
我正在下载的文件是一个 dll,我的问题是它正在以某种方式被这个过程改变。我知道这是因为文件大小在增加。我怀疑这部分代码有问题:
destination.Write(reader.ReadToEnd());
destination.Flush();
任何人都可以就可能出现的问题提供任何想法吗?