Solved

GetFileInformationByHandle

Posted on 2006-06-13
3
515 Views
Last Modified: 2013-11-20
I am downloading a file from a remote ftp site.  I want to check the ftp filename creation date time to make sure I dont donwload thesame file twice.

GetFileInformationByHandle is not returning the correct file creation date & time of an FTP file.

What's wrong with this code???

I have this code:

      BOOL bDestFileOpen=FALSE;
      CInternetFile*  ifp=NULL;
      try
      {
            ifp = m_Ftp_Conn->OpenFile(source);
            if(ifp)
            {
                  DWORD dwSizeHigh;
                  DWORD dwSizeLow;
                  BY_HANDLE_FILE_INFORMATION info;
                  ::GetFileInformationByHandle( ifp->m_hFile, &info );
                  dwSizeHigh = info.nFileSizeHigh;
                  dwSizeLow = info.nFileSizeLow;            //this will handle up to 4GIG

...
                  CTime fileTime(info.ftCreationTime.dwLowDateTime);
                  CString temp;
                  temp.Format(L"File Date = %02d/%02d/%04d Time = %02d:%02d:%04d",
                        fileTime.GetMonth(),fileTime.GetDay(),fileTime.GetYear(),
                        fileTime.GetHour(),fileTime.GetMinute(),fileTime.GetSecond());
            
0
Comment
Question by:ramrocket
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16897771
As the docs state: "Depending on the underlying network components of the operating system and the type of server connected to, the GetFileInformationByHandle function may fail, return partial information, or full information for the given file."

I'd rather suggest to

LPWIN32_FIND_DATA wfd;

HINTERNET hFind = FtpFindFirstFile(fp->m_hFile,source,wfd,INTERNET_FLAG_DONT_CACHE,0);

InternetCloseHandle(hFind);

               CTime fileTime(wfd.ftCreationTime.dwLowDateTime);
               CString temp;
               temp.Format(L"File Date = %02d/%02d/%04d Time = %02d:%02d:%04d",
                    fileTime.GetMonth(),fileTime.GetDay(),fileTime.GetYear(),
                    fileTime.GetHour(),fileTime.GetMinute(),fileTime.GetSecond());
         
0
 

Author Comment

by:ramrocket
ID: 16897921
jkr, it would crash on the call to CTime fileTime(wfd->ftCreationTime.dwLowDateTime);
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 16899168
>>it would crash on the call to CTime fileTime(wfd->ftCreationTime.dwLowDateTime);

Sorry, typo, that should be

WIN32_FIND_DATA wfd;

HINTERNET hFind = FtpFindFirstFile(fp->m_hFile,source,wfd,INTERNET_FLAG_DONT_CACHE,0);

InternetCloseHandle(hFind);

               CTime fileTime(wfd.ftCreationTime.dwLowDateTime);
               CString temp;
               temp.Format(L"File Date = %02d/%02d/%04d Time = %02d:%02d:%04d",
                    fileTime.GetMonth(),fileTime.GetDay(),fileTime.GetYear(),
                    fileTime.GetHour(),fileTime.GetMinute(),fileTime.GetSecond());
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question