write time on FTP server is very off
im trying to compare file write times between a local file and a file on an ftp server. the file times on the local machine work and it makes sense, but when I look at the file on the ftp server it shows two different times, via windows explorer and rightclick->properties. I found out a hack that works and its commented in my code. Any help? I want the file times to relate to each other correctly. MFC, C++, Windows 7 32bit, VS 2008
Code:
HINTERNET xmlHandle = NULL;
WIN32_FIND_DATA ftpFileData;
// find the file on the ftp server
xmlHandle = FtpFindFirstFile( m_ftpHandle, _T("TPCFeed.xml"), &ftpFileData, INTERNET_FLAG_RELOAD, 开发者_JS百科0 );
if( NULL != xmlHandle )
{
//-----------------------------------------------------------------------------------
// get the write time of the ftp file
SYSTEMTIME ftpFileWriteTime,
stUTC1;
FILETIME ftp;
FileTimeToSystemTime( &ftpFileData.ftLastWriteTime, &stUTC1 );
SystemTimeToTzSpecificLocalTime( NULL, &stUTC1, &ftpFileWriteTime );
// ----- HACK -------------------------------------------
ftpFileWriteTime.wHour += 4; // this hack works
SystemTimeToFileTime( &ftpFileWriteTime, &ftp );
//-----------------------------------------------------------------------------------
// get the write time of the local file
HANDLE localFileHandle = NULL;
localFileHandle = CreateFile( _T(_XML_FILENAME_PATH), FILE_READ_ATTRIBUTES,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
NULL, NULL );
if( INVALID_HANDLE_VALUE != localFileHandle )
{
// get local file time
FILETIME localFileWriteTime,
local;
GetFileTime( localFileHandle, NULL, NULL, &localFileWriteTime );
SYSTEMTIME localFileWriteTime1,
stUTC;
FileTimeToSystemTime( &localFileWriteTime, &stUTC );
SystemTimeToTzSpecificLocalTime( NULL, &stUTC, &localFileWriteTime1 );
SystemTimeToFileTime( &localFileWriteTime1, &local );
//-----------------------------------------------------------------------------------
int timeResult = CompareFileTime( &ftp, &local );
if( -1 == timeResult )
AfxMessageBox( _T( "file on disk is later than ftp file, no need to download anything" ) );
else if( 0 == timeResult )
AfxMessageBox( _T( "times are equal!" ) );
else if( 1 == timeResult )
AfxMessageBox( _T( "file on ftp server is later than file on disk" ) );
SystemTimeToTzSpecificLocalTime( NULL, &stUTC1, &ftpFileWriteTime )
That doesn't work. You'd have to pass the time zone in which the server lives, not your own time zone. Assuming that the server even sends UTC time stamps, that wasn't common the last time I gave up on it. Finding out what timezone it lives in ought to be challenging. FTP hasn't matured well.
精彩评论