Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget :: rename downloaded files and only download if newer

Tags:

wget

I am trying to use wget to download a file under a different local name and only download if the file on the server is newer.

What I thought I could do was use the -O option of wget so as to be able to choose the name of the downloaded file, as in:

wget http://example.com/weird-name -O local-name

and combine that with the -N option that doesn't download anything except if the timestamp is newer on the server. For reasons explained in the comments below, wget refuses to combine both flags:

WARNING: timestamping does nothing in combination with -O. See the manual
for details.

Any ideas on succinct work-arounds ?

like image 588
Marcus Junius Brutus Avatar asked Sep 22 '13 21:09

Marcus Junius Brutus


2 Answers

Download it, then create a link

wget -N example.com/weird-name
ln weird-name local-name

After that you can run wget -N and it will work as expected:

  • Only download if newer
  • If a new file is downloaded it will be accessible from either name, without costing you extra drive space
like image 159
Zombo Avatar answered Sep 30 '22 12:09

Zombo


If using other tool is possible in your case, I recommend the free, open source lwp-mirror:

lwp-mirror [-options] <url> <file>

It works just as you wish, with no workarounds.

This command is provided by the libwww-perl package on Ubuntu and Debian among other places.

Note that lwp-mirror doesn't support all of wget's other features. For example, it doesn't allow you to set a User Agent for the request like wget does.

like image 43
Mark Stosberg Avatar answered Sep 30 '22 10:09

Mark Stosberg