Get File Creation Date Over HTTP

后端 未结 3 967
南旧
南旧 2021-01-11 18:34

Given a file on a webserver (e.g., http://foo.com/bar.zip -> only accessible through HTTP), is there any way to get the date attributes (e.g., date [created, modified]) with

相关标签:
3条回答
  • 2021-01-11 18:54

    Just for the sake of simplicity, here's a compilation of the existing (perfect) answers from @ihorko and @JanThomä, that uses curl. Other option are available too, of course, but here's a fully functional answer.

    Use curl with the -I option:

    -I, --head
    (HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl displays the file size and last modification time only.

    Also, the -s option is nice here:

    -s, --silent
    Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

    Hence, something like this would do the trick:

    curl -sI http://foo.com/bar.zip | grep 'Last-Modified' | cut -d' ' -f 2-
    
    0 讨论(0)
  • 2021-01-11 18:56

    Try to read Last-Modified from header

    0 讨论(0)
  • 2021-01-11 19:11

    Be sure to use a HTTP HEAD request instead of a HTTP GET request to read the HTTP headers only. If you do a HTTP GET, you will download the whole file nevertheless, even if you decide just to inspect the HTTP headers.

    0 讨论(0)
提交回复
热议问题