2

I was wondering if CURL allows you to do the same function as WGET -N does - which will only download / overwrite a file if the existing file on the client side is older than the one on the server.

Tamzin
  • 79
  • 1
  • 6

2 Answers2

3

I realise this question is old now, but just in case someone else is looking for the answer, it seems that cURL can indeed acheieve similar to wget -N.

Because I was just looking for an answer to this question today, and I found elsewhere that cURL does have time condition option. If google brings you here first, as it did me, then I hope this answer might save you some time in looking. According to curl --help, there is a time-cond flag;

-z, --time-cond <time> Transfer based on a time condition

The other part I needed, in order to make it like wget -N, is to make it try and preserve the timestamp. This is with the -R option.

-R, --remote-time   Set the remote file's time on the local output

We can use these to download "$file", only in the condition when the current local "$file" timestamp is older than the server's file timestamp; we can do it in this form;

curl -R -o "$file" -z "$file" "$serverurl"

So, for example, I use it to check if there is a newer cygwin installer like this;

curl -R -o "C:\cygwin64\setup-x86_64.exe" -z "C:\cygwin64\setup-x86_64.exe" "https://www.cygwin.com/setup-x86_64.exe"
mernst
  • 7,437
  • 30
  • 45
2

cURL doesn't have the same type of mirroring support that wget has built in. There is one setting in there with cURL that should make it pretty easy to implement this for yourself though with a little bit of wrapping logic. It's the --remote-time option:

   -R/--remote-time
          When  used,  this  will  make  libcurl attempt to figure out the
          timestamp of the remote file, and if that is available make the
          local file get that same timestamp.
James C
  • 14,047
  • 1
  • 34
  • 43