I have this method to transfer files using a FTP Server:
private void TransferNeededFiles(IEnumerable<string> filenames)
{
foreach (var filename in filenames)
{
var request = WebRequest.Create(new Uri(@"ftp://{0}/{1}".Fill(Config.ServerUri, filename))) as FtpWebRequest;
if (request != null)
{
request.Credentials = new NetworkCredential(Config.Username, Config.Password);
request.Method = WebRequestMethods.Ftp.DownloadFile;
using (var streamReader = new StreamReader(request.GetResponse().GetResponseStream()))
{
var fileStream = new FileStream(@"{0}/{1}".Fill(Config.DestinationFolderPath, filename), FileMode.Create);
var writer = new StreamWriter(fileStream);
writer.Write(streamReader.ReadToEnd());
writer.Flush();
writer.Close();
fileStream.Close();
}
}
}
}
A .gz file, included in the list of filenames, is always corrupted. When I try to copy from ftp using windows explorer, the file is not corrupted. Do you know what is happening?