下面的代码是MSDN上面的,可是取得的ftp服务器文件的时间都是“1970.01.01 08:00”,有人遇到过这个问题吗?
CInternetSession sess(_T("MyProgram/1.0"));CFtpConnection* pConnect = NULL;try
{
pConnect = sess.GetFtpConnection("192.168.47.249", "xinw2", "123"); // use a file find object to enumerate files
CFtpFileFind finder(pConnect); // start looping
BOOL bWorking = finder.FindFile(_T("*")); while (bWorking)
{
CString strTime;
CTime time;
bWorking = finder.FindNextFile();
finder.GetLastAccessTime(time);
strTime = time.Format("%Y.%m.%d %H:%M");
AfxMessageBox(strTime); // 这里取得的时间都是“1970.01.01 08:00” }
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf_s("ERROR! %s\n", sz);
pEx->Delete();
}// if the connection is open, close it
if (pConnect != NULL)
{
pConnect->Close();
delete pConnect;
}
CInternetSession sess(_T("MyProgram/1.0"));CFtpConnection* pConnect = NULL;try
{
pConnect = sess.GetFtpConnection("192.168.47.249", "xinw2", "123"); // use a file find object to enumerate files
CFtpFileFind finder(pConnect); // start looping
BOOL bWorking = finder.FindFile(_T("*")); while (bWorking)
{
CString strTime;
CTime time;
bWorking = finder.FindNextFile();
finder.GetLastAccessTime(time);
strTime = time.Format("%Y.%m.%d %H:%M");
AfxMessageBox(strTime); // 这里取得的时间都是“1970.01.01 08:00” }
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf_s("ERROR! %s\n", sz);
pEx->Delete();
}// if the connection is open, close it
if (pConnect != NULL)
{
pConnect->Close();
delete pConnect;
}
否则自己发送LIST命令,解析返回数据就是了。想要MSDN上面的取得的ftp服务器文件的正确的话,Ftp Server是IIS下带的还差不多。
如果文件的最后修改日期是今年,返回的信息中就没有年份信息;
如果文件的最后修改日期是去年或更久,则返回的信息中有年份信息,但是没有小时、分等信息。另外我们使用的FTP工具都可以正确取得服务器上的文件的时间信息,它们是怎么做的,有了结的吗?