如何通过HH-MM-SS时间戳格式从远程sftp服务器获取文件列表

时间:2020-06-24 14:14:44

标签: c++ ftp libcurl

我正在编写一个小应用程序,该应用程序使用Curl从远程sftp服务器读取文件列表。在获取文件列表并进行解析时,这不是问题:

   curl_easy_setopt(m_pCurlSession, CURLOPT_WRITEFUNCTION, Callback);
   curl_easy_setopt(m_pCurlSession, CURLOPT_URL, "sftp://xxxx.xx:22/");
   curl_easy_setopt(m_pCurlSession, CURLOPT_USERNAME, "xxxx");
   curl_easy_setopt(m_pCurlSession, CURLOPT_PASSWORD, "xxxx");
   curl_easy_setopt(m_pCurlSession, CURLOPT_USE_SSL, static_cast<long>(CURLUSESSL_ALL));
   curl_easy_setopt(m_pCurlSession, CURLOPT_VERBOSE, 1);
   curl_easy_perform(m_pCurlSession);

我得到的输出是这个

drwxrwxr-x    3 root     root       4096 Jun 23 16:21 .
drwxr-xr-x    4 root     root       4096 Jun 15 08:59 ..
 drwxrwxr-x    2 user     user      4096 Jun 23 17:11 IMAGES
 -rw-rw-r--    1 user     user    152069 Jun 23 16:20 test.xml

您可以看到最后修改的文件的时间戳是HH:MM,但是由于我的应用需要比较本地和远程文件的最后修改的时间戳,因此我还需要查看秒数,以便进行比较。 / p>

在使用Filezilla客户端进行测试时,我可以看到正确的时间戳记,因此我可以确定这不是服务器端的问题。

使用带有SFTP的libcurl发出LIST时,如何获得正确的时间戳?

2 个答案:

答案 0 :(得分:1)

我不认为libcurl是适合此的库。

尝试libssh或libssh2:

答案 1 :(得分:0)

通过获取文件列表,解析到相关的文件列表并分别获取每个文件的时间戳来解决。

相关问题