FTP 服务器上的写入时间非常短
我正在尝试比较本地文件和 ftp 服务器上的文件之间的文件写入时间。本地计算机上的文件时间有效并且有意义,但是当我查看 ftp 服务器上的文件时,它显示两个不同的时间,通过 Windows 资源管理器和右键单击 -> 属性。我发现了一个有效的 hack,并在我的代码中对其进行了注释。有什么帮助吗?我希望文件时间能够正确地相互关联。 MFC、C++、Windows 7 32 位、VS 2008
代码:
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, 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" ) );
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, 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" ) );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不起作用。您必须传递服务器所在的时区,而不是您自己的时区。假设服务器甚至发送 UTC 时间戳,上次我放弃它时这种情况并不常见。找出它所在的时区应该是具有挑战性的。 FTP还没有成熟。
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.