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

问题描述 投票:0回答:2

我正在编写一个小应用程序,它使用 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,但由于我的应用程序需要比较本地和远程文件的上次修改时间,我还需要查看秒数,以便进行比较。

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

使用 libcurl 和 SFTP 发出

LIST
时如何获得正确的时间戳?

c++ sftp libcurl
2个回答
1
投票

我不认为 libcurl 是一个很好的库。

尝试 libssh 或 libssh2:


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.