xref: /curl/docs/libcurl/opts/CURLOPT_FILETIME.md (revision e3fe0200)
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
16---
17
18# NAME
19
20CURLOPT_FILETIME - get the modification time of the remote resource
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FILETIME, long gettime);
28~~~
29
30# DESCRIPTION
31
32Pass a long. If it is 1, libcurl attempts to get the modification time of the
33remote document in this operation. This requires that the remote server sends
34the time or replies to a time querying command. The curl_easy_getinfo(3)
35function with the CURLINFO_FILETIME(3) argument can be used after a
36transfer to extract the received time (if any).
37
38# DEFAULT
39
400
41
42# EXAMPLE
43
44~~~c
45int main(void)
46{
47  CURL *curl = curl_easy_init();
48  if(curl) {
49    CURLcode res;
50    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/path.html");
51    /* Ask for filetime */
52    curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
53    res = curl_easy_perform(curl);
54    if(CURLE_OK == res) {
55      long filetime;
56      res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
57      if((CURLE_OK == res) && (filetime >= 0)) {
58        time_t file_time = (time_t)filetime;
59        printf("filetime: %s", ctime(&file_time));
60      }
61    }
62    /* always cleanup */
63    curl_easy_cleanup(curl);
64  }
65}
66~~~
67
68# AVAILABILITY
69
70Always, for SFTP since 7.49.0
71
72# RETURN VALUE
73
74Returns CURLE_OK
75