I have a Perl script which downloads a large number of files from a remote server. I’d like to avoid hammering the server, so I’d like to avoid downloading a file if it hasn’t been modified since my last check. Is there a good way to do this, either in Perl or with a shell script?
Can I get the server to send HTTP 304 rather than HTTP 200 for unmodified files?
Yes, use
LWP::UserAgentand pay special attention to themirrormethod. This is also available in the proceduralLWP::Simpleas themirrorfunction.From
LWP‘s POD:HTTP 304 is the response code the server will return if you pass the If-Modified-Since test and your copy is fresh. LWP does this internally with
mirror— you needn’t worry about it.