Solved

GetFileInformationByHandle

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 75
iSeries DB2 Query 2 90
Shell script to login to remote m/c and execute commands 10 78
maxBlock challenge 30 111
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

16 Experts available now in Live!

Get 1:1 Help Now