FTP 服务器上的写入时间非常短

发布于 2024-09-16 23:29:21 字数 2719 浏览 10 评论 0原文

我正在尝试比较本地文件和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的心爱 2024-09-23 23:29:21

SystemTimeToTzSpecificLocalTime( NULL, &stUTC1, &ftpFileWriteTime )

这不起作用。您必须传递服务器所在的时区,而不是您自己的时区。假设服务器甚至发送 UTC 时间戳,上次我放弃它时这种情况并不常见。找出它所在的时区应该是具有挑战性的。 FTP还没有成熟。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文