1
我正在使用此代码通过FTP从服务器下载文件。它正常工作,几乎所有的扩展(PDF,HTML,JPG ...),但由于某些原因,所有的zip文件被下载了一些误差修改:单击 - 通过FTP下载时出错(多个压缩文件)
public static FtpStatusCode Download(string destinationFile, Uri downloadUri, string userName, string password)
{
try
{
if (downloadUri.Scheme != Uri.UriSchemeFtp)
{
throw new ArgumentException("Invalid FTP site");
}
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(downloadUri);
ftpRequest.Credentials = new NetworkCredential(userName, password);
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpRequest.UseBinary =true;
ftpRequest.UsePassive = true;
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream stream = null;
StreamReader reader = null;
StreamWriter writer = null;
try
{
stream = ftpResponse.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);
writer = new StreamWriter(destinationFile, false);
writer.Write(reader.ReadToEnd());
return ftpResponse.StatusCode;
}
finally
{
stream.Close();
reader.Close();
writer.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}
有谁知道原因或可以告诉一个解决方案吗?
问候,
克劳迪奥
你为什么要设置Encoding.UTF8? – Gabe 2011-02-03 04:15:42
我下载的一些文件需要使用UTF8格式。但即使没有这种编码,zip文件也会出错。 – Claudio 2011-02-03 05:04:41