Solved

GetFileInformationByHandle

Posted on 2006-06-13
3
505 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now