{"id":14290,"date":"2020-06-29T13:01:48","date_gmt":"2020-06-29T11:01:48","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=14290"},"modified":"2020-06-29T13:01:48","modified_gmt":"2020-06-29T11:01:48","slug":"curl-ootw-remote-time","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2020\/06\/29\/curl-ootw-remote-time\/","title":{"rendered":"curl ootw: &#8211;remote-time"},"content":{"rendered":"\n<p><a href=\"https:\/\/daniel.haxx.se\/blog\/2020\/01\/07\/curl-option-of-the-week\/\">Previous command line options of the week.<\/a><\/p>\n\n\n\n<p><code>--remote-time<\/code> is a boolean flag using the <code>-R<\/code> short option. This option was added to curl 7.9 back in September 2001.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Downloading a file<\/h2>\n\n\n\n<p>One of the most basic curl use cases is &#8220;downloading a file&#8221;. When the URL identifies a specific remote resource and the command line transfers the data of that resource to the local file system:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl https:\/\/example.com\/file -O<\/pre>\n\n\n\n<p>This command line will then copy every single byte of that file and create a duplicated resource locally &#8211; <em>with a time stamp using the current time<\/em>. Having this time stamp as a default seems natural as it was created just now and it makes it work fine with other options such as <code><a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-z\">--time-cond<\/a><\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use the remote file&#8217;s time stamp please<\/h2>\n\n\n\n<p>There are times when you rather want the download to get the exact same modification date and time as the remote file has. We made <code>--remote-time<\/code> do that.<\/p>\n\n\n\n<p>By adding this command line option, curl will figure out the exact date and time of the remote file and set that same time stamp on the file it creates locally.<\/p>\n\n\n\n<p>This option works with several protocols, including FTP, but there are and will be many situations in which curl cannot figure out the remote time &#8211; sometimes simply because the server won&#8217;t tell &#8211; and then curl will simply not be able to copy the time stamp and it will instead keep the current date and time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Not be default<\/h2>\n\n\n\n<p>This option is not by default because.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>curl mimics known tools like cp which creates a new file stamp by default.<\/li><li>For some protocols it requires an extra operation which then can be avoided if the time stamp isn&#8217;t actually used for anything.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Combine this with&#8230;<\/h2>\n\n\n\n<p>As mentioned briefly above, the <code>--remote-time<\/code> command line option can be really useful to combine with the <code>--time-cond<\/code> flag. An example of a practical use case for this is a command line that you can invoke repeatedly, but only downloads the new file in case it was updated remotely since the previous time it was downloaded! Like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curl <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-O\">--remote-name<\/a> <a href=\"https:\/\/curl.haxx.se\/docs\/manpage.html#-z\">--time-cond<\/a> cacert.pem https:\/\/curl.haxx.se\/ca\/cacert.pem<\/pre>\n\n\n\n<p>This particular example comes from the <a href=\"https:\/\/curl.haxx.se\/docs\/caextract.html\">curl&#8217;s CA extract web page<\/a> and downloads the latest Mozilla CA store as a PEM file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previous command line options of the week. &#8211;remote-time is a boolean flag using the -R short option. This option was added to curl 7.9 back in September 2001. Downloading a file One of the most basic curl use cases is &#8220;downloading a file&#8221;. When the URL identifies a specific remote resource and the command line &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2020\/06\/29\/curl-ootw-remote-time\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">curl ootw: &#8211;remote-time<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":13041,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[33,486],"class_list":["post-14290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-floss","tag-curl-and-libcurl","tag-option-of-the-week"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/14290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=14290"}],"version-history":[{"count":8,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/14290\/revisions"}],"predecessor-version":[{"id":14372,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/14290\/revisions\/14372"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media\/13041"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=14290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=14290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=14290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}