Solved

GetFileInformationByHandle

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
FizzBuzz challenge 9 87
fix34  challenge 9 181
Trying to run powershell  in a batch file. How do I do this? 8 124
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

759 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