如何从远程 SFTP 服务器获取 HH-MM-SS 时间戳格式的文件列表
How to get the file list with from a remote SFTP server in HH-MM-SS timestamp format
我正在编写一个小应用程序,它使用 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
,如何获得正确的时间戳?
我不认为libcurl是很好的库。
尝试 libssh 或 libssh2:
-
libssh:调用
sftp_opendir
,然后反复sftp_readdir
,最后sftp_closedir
。您将在
sftp_attributes_struct
mtime
字段中获得完整的时间戳。 -
libssh2:调用
libssh2_sftp_opendir
,然后反复libssh2_sftp_readdir
,最后libssh2_sftp_closedir
。您将在
mtime
字段中获得完整的时间戳LIBSSH2_SFTP_ATTRIBUTES
.
通过获取文件列表、解析到相关文件列表并分别获取每个文件时间戳来解决。
相关文章:
- 如何在C++中将 chrono::秒转换为 HH:MM:SS 格式的字符串?
- 如何从远程 SFTP 服务器获取 HH-MM-SS 时间戳格式的文件列表
- 将 hh:mm:ss.zzz 时间 QString 转换为毫秒的单行函数?
- 格式化时间 c++ dd/mm/yyyy hh:ss.
- 如何在C++中将秒更改为 HH:MM:SS 格式?
- 如何以"hh:mm:ss"格式读取C ++中的HH,MM和SS
- 在 C++11 中表示日内时间 HH:MM:SS 的最佳方法是什么?
- C - 用STD :: difftime编写调度程序 - 如何在白天检查时间(HH:MM:SS)
- 以 hh:mm 格式添加时间,C++
- 如何将EPOCH时间转换为时间格式(hh:mm)
- C++字符串 DD:HH:MM:SS 到整数数据类型
- 将军事时间转换为标准格式(HH:MM)并以标准格式计算平均值.三个问题
- 时间格式 HH:MM:SS 输入
- 将日期格式Www-Mmm-dd hh:mm:ss yyyy转换为c++中的dd hh:mm:ss字符串
- 如何将CFAbsoluteTime转换为YYYY-MM-DD HH:MM:SS格式?
- 两个时间之间经过的时间,格式为24小时hh:mm:ss
- 获取以毫秒为单位的当前时间,或HH:MM:SS:MMM格式
- Qt C++将秒转换为格式化字符串(hh:mm:ss)
- 如何将 YYYY/MM/DD HH:MM:SS 转换为标准::时间::system_clock::time_point
- 如何比较格式的两个时间戳"Month Date hh:mm:ss"以检查 +ve 或 -ve 值