Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Clac CRC before downloading (https://www.delphipraxis.net/150512-clac-crc-before-downloading.html)

sdean 19. Apr 2010 15:22


Clac CRC before downloading
 
Hi , i use indy 'idhttp' to download files , But what i want is :

Before begin downloading a file from server i should calc its CRC why :
because i must be sure if this file has not already been downloaded and saved .

please is there any way or other alternative to acheive that ? .

wicht 19. Apr 2010 15:26

Re: Clac CRC before downloading
 
Hi,

this might not be possible because you can calculate the CRC only if you already downloaded the file I think. Is this over HTTP? I think there is no HTTP command to get the checksum of a remote file.

HTH

sdean 19. Apr 2010 15:40

Re: Clac CRC before downloading
 
yes over HTTP , let me suppose the following scenario :

yesterday i downloaded x0.myfile which CRC is 3361685294 , and today i want to download other files among of them is x0.myfile so when the download process starts it should bypass x0.myfile because it's already downloaded yesterday .

That's what i want to acheive .

Yes i can use If FileExists(x0.myfile) then bypass , But here i want to work with CRC , MD5 or whatever


any idea wicht ?

lbccaleb 19. Apr 2010 15:47

Re: Clac CRC before downloading
 
You can also check the Filesize before downloading the file!

sdean 19. Apr 2010 15:53

Re: Clac CRC before downloading
 
Thank you lbccaleb :

But it can be possible 2 files have the same size !

I think the better way is to use the CRC or MD5

lbccaleb 19. Apr 2010 16:00

Re: Clac CRC before downloading
 
I have found this. But its only german.

HeikoAdams 19. Apr 2010 16:04

Re: Clac CRC before downloading
 
Is the file you want to download a file provided by you? If yes you could also provide a textfile containing the checksum of that file which will be downloaded first. After that you could download the main-file and compare its checksum with the checksum from your textfile.

IMHO there is no way to calc a checksum of a file placed on a webserver without downloading that file to your local computer.

generic 19. Apr 2010 16:16

Re: Clac CRC before downloading
 
you cant build a crc on a url without downloading the file!

but you can request via HEAD the headers to a file.
with the header you can compare the size, date and most important the Etag.

sdean 19. Apr 2010 16:22

Re: Clac CRC before downloading
 
Thank you HeikoAdams , that's a good idea , Ok then let me suppose this :

i place an ini file in my webserver :
update.ini

[File01]
Name=x0.myfile
checksum=3361685294
[File02]
Name=x1.myfile
checksum=3361685295
.
.
.

Then should i download x0.myfile to compare its checksum with the already downloaded one or what ?

sdean 19. Apr 2010 16:24

Re: Clac CRC before downloading
 
Thank you generic, could you explain more , or give me a little exemple for that

generic 19. Apr 2010 16:45

Re: Clac CRC before downloading
 
Look here:
http://en.wikipedia.org/wiki/HTTP_ETag
the german one is better:
http://de.wikipedia.org/wiki/HTTP_ETag
and
http://solariz.de/2044/etag_webseite...chleunigen.htm

Depending on the Webserver you have a strong Etag or not.
Strong ETags using checksums.
Weak ETags you can detect on "W/" before the Etag-Code.
last link uses php code for MD5-Etaging

Delphi-Quellcode:
uses
  MSXML2_TLB;

var
  req : IXMLHTTPRequest;
  str_link: string;
begin
  req := CoXMLHTTP40.Create;
  str_link:='http://linktofile';
  req.Open('HEAD', str_link, False, EmptyParam, EmptyParam);
  req.send(EmptyParam);
  // check for req.status=200 -> if true no error
  MessageDlg(req.getAllResponseHeaders(), mtWarning, [mbOK], 0);
  MessageDlg(req.getResponseHeader('Etag'), mtWarning, [mbOK], 0);

  req:=nil;
end;

the headers may look like:
Code:
Date   Mon, 19 Apr 2010 15:45:57 GMT
Server   Apache
Pragma   public
Expires   Mon, 19 Apr 2010 16:34:07 GMT
Last-Modified   Mon, 19 Apr 2010 15:34:07 GMT
Cache-Control   max-age=2890, public, must-revalidate, proxy-revalidate Vary   Accept-Encoding,Cookie,User-Agent
Etag   7e828ab2622e112d6a6bd3b7083a560b
Content-Encoding   gzip
Content-Type   text/html; charset=UTF-8

SirThornberry 19. Apr 2010 17:06

Re: Clac CRC before downloading
 
@sdean: please dont push within 24 hours. If you want to add any information during this time, you can use the edit-button at the top of your last entry.

sdean 19. Apr 2010 17:24

Re: Clac CRC before downloading
 
@SirThornberry : Sorry for that


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:59 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz