xref: /curl/docs/libcurl/opts/CURLOPT_FILETIME.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_FILETIME
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_FILETIME (3)
9  - curl_easy_getinfo (3)
10Protocol:
11  - HTTP
12  - FTP
13  - SFTP
14  - FILE
15  - SMB
16Added-in: 7.5
17---
18
19# NAME
20
21CURLOPT_FILETIME - get the modification time of the remote resource
22
23# SYNOPSIS
24
25~~~c
26#include <curl/curl.h>
27
28CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FILETIME, long gettime);
29~~~
30
31# DESCRIPTION
32
33Pass a long. If it is 1, libcurl attempts to get the modification time of the
34remote document in this operation. This requires that the remote server sends
35the time or replies to a time querying command. The curl_easy_getinfo(3)
36function with the CURLINFO_FILETIME(3) argument can be used after a
37transfer to extract the received time (if any).
38
39# DEFAULT
40
410
42
43# %PROTOCOLS%
44
45# EXAMPLE
46
47~~~c
48int main(void)
49{
50  CURL *curl = curl_easy_init();
51  if(curl) {
52    CURLcode res;
53    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/path.html");
54    /* Ask for filetime */
55    curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
56    res = curl_easy_perform(curl);
57    if(CURLE_OK == res) {
58      long filetime;
59      res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
60      if((CURLE_OK == res) && (filetime >= 0)) {
61        time_t file_time = (time_t)filetime;
62        printf("filetime: %s", ctime(&file_time));
63      }
64    }
65    /* always cleanup */
66    curl_easy_cleanup(curl);
67  }
68}
69~~~
70
71# %AVAILABILITY%
72
73# RETURN VALUE
74
75Returns CURLE_OK
76