Solved Request: download a file if and only if its size changes

December 9, 2014 at 11:33:59
Specs: Windows XP, C2D 1.66 Ghz
I'd like a batch file to do the following:

* Read the expected file size of the target file (in bytes) from a save file.
* Connect to the server hosting the target file and query its file size (in bytes).
* If the two values match, quit. If they don't, download the target file to a specific local path (overwriting the current instance) and update the file size value in the save file.

I use curl for command-line downloading, but I can probably adapt solutions using other tools.


See More: Request: download a file if and only if its size changes

Report •

December 9, 2014 at 20:47:16
No "turn-key" solution, since I don't have CURL.exe that will execute on my system. I use WGET which has an option to "don't download anything" and gives me the file's size without having to download it. WGET is also recalcitrant in that it will not pipe out. It always reports directly to CONSOLE unless you invoke the alternate-output option. FWIW here's the wget version:
@echo off & setlocal
set target=VB40032
if not exist %target% (
goto :eof
@echo off & setlocal
for /f "tokens=2" %%a in ('curl -I^|find /i "content-length:"') do set size=%%a
echo size:%size%
:: get local file's size from the directory entry
for %%a in (%TARGET%) do set cmpare=%%~za
echo local: %cmpare% -- server: %size%
if %cmpare% neq %size% (
echo sized diff, downloading new:
wget -O %target%
I saw no reason to store the local file's size, since it is most dependably obtained from the directory entry for the file.

message edited by nbrane

Report •

December 10, 2014 at 10:36:57
This does most of what I need, thanks, but modifying it to use curl could be beyond me.

If you tell me your OS, I can try to find a version of curl that will run on your system, so you can test with it, and modify accordingly, if you would.

Report •

December 10, 2014 at 21:26:58
✔ Best Answer
na, don' worry bout it. I got cURL to work on my 7 (just neede msvcr110.dll renamed from msvcr110_clr0400.dll). I slogged through the options, and came up with this:
::===== begin batch snippet
@echo off & setlocal
for /f "tokens=2" %%a in ('curl -I^|find /i "content-length:"') do set size=%%a
::========= end snip
the rest is same from ":: get local file's size" on down.

Report •
Related Solutions

Ask Question