我正在编写一个使用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发布列表时获得正确的时间戳?
我不认为libcurl是一个好库。
尝试libssh及其sftp_readdir
函数和sftp_attributes_struct
: