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