1
I created a windows service, which daily downloads some files. These files have about 2Gb (that’s right, two gigabytes!).
The problem is that these files are every day available on the site, but are updated randomly weekly, IE, I can not determine when these files are updated.
Files always have the same name, so the same url.
How can I check if the file on the site is newer than the file I’ve already downloaded?
The intention is not to keep downloading the files unnecessarily.
Below my download function :
private void FazDownload(string fileUrlToDownload, string Saida)
{
WebRequest getRequest = WebRequest.Create(fileUrlToDownload);
getRequest.Headers.Add("Cookie", CookieAutenticacao);
try
{
using (WebResponse getResponse = getRequest.GetResponse())
{
log.Info("Fazendo download de " + fileUrlToDownload);
string OutPutfileFullPath = Saida;
#region Se não existir o diretório então cria o diretório.
if (!Directory.Exists(Path.GetDirectoryName(OutPutfileFullPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(OutPutfileFullPath));
}
#endregion
using (var fileStream = File.Create(OutPutfileFullPath, 8092))
{
getResponse.GetResponseStream().CopyTo(fileStream);//Download e escrita em arquivo.
}
log.Info(String.Format("Download de {0} realizado com sucesso e gravado em {1}.", fileUrlToDownload, OutPutfileFullPath));
}
}
catch (System.Net.WebException)
{
log.Warn("Arquivo não encontrado em " + fileUrlToDownload);
}
}
There is no way for you to get the file’s HASH and compare with what you have on the user’s pc?
– Metalus