Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get File Creation Date Over HTTP

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]) without downloading the entire archive in the first place?

Right now, I download the archive and read the attributes programmatically. Trouble is that the archive is dozens of MiB so it seems like a waste of resources to download the entire thing and end up reading off just a couple of bytes of information.

I realize that bandwidth is practically free, but I don't like to be wasteful in any case.

like image 697
consq18 Avatar asked Dec 01 '10 16:12

consq18


People also ask

How do I find the actual creation date of a file?

Choose File. Select Properties. Click the Description tab. Find the creation date and time near the title and author.

How can I tell when an Android file was created?

Android's emulated filesystem does not store the creation date of files or folders, so there is no way to retrieve this data, as it does not exist. (Many thanks to Irfan Latif for confirming this, and to Izzy for clarifications.)

How do I change the file properties of a date?

Click the Change Time/Attributes button (indicated below). A new window will open with details of what properties you can change. Enable the checkbox next to 'Created' and set the exact date and time that you want to set as the file's creation date.


3 Answers

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-
like image 193
Benoit Duffez Avatar answered Oct 01 '22 05:10

Benoit Duffez


Try to read Last-Modified from header

like image 37
ihorko Avatar answered Oct 01 '22 04:10

ihorko


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.

like image 22
Jan Thomä Avatar answered Oct 01 '22 04:10

Jan Thomä