Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : FtpFindFirstFile and date problem

www.cryer.info
Managed Newsgroup Archive

FtpFindFirstFile and date problem

Subject:FtpFindFirstFile and date problem
Posted by:"dpap" (dp..@softwaypro.gr)
Date:Thu, 25 May 2006 22:13:31

Hi,

I wrote the code bellow to get the listing of a directory on a FTP server

procedure getDirectory(directory : string);
     var hDir : HInternet;
         pDirInfo : WIN32_FIND_DATA;
         s : string;
       fTime : integer;
        sRec : TsearchRec;
        wLT : TFILETIME;
        wST : TSystemTime;
        localFileTime : TDateTime;
     begin
          FtpSetCurrentDirectory(hURL, PChar(directory));
{idFTP1.ChangeDir('/httpdocs/Files/'+directory);
idFTP1.list(memo2.lines); }

            hDir := FtpFindFirstFile(hURL, '*.*', pDirInfo,
INTERNET_FLAG_RELOAD, 0);
            if hDir <> nil then begin
             repeat
              if (pDirInfo.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) =
0
                    then with pDirInfo, ftLastWriteTime do begin
                       FileTimeToLocalFileTime(ftLastWriteTime, wLT);
                      FileTimeToSystemTime(wLT, wST);
                        with wST do begin
                         localFileTime := encodeDate(wST.wYear, wST.wMonth,
wST.wDay);
                         ReplaceTime(localFileTime,encodeTime(whour,wminute,wsecond,wmilliseconds));
                        end;
                     s := directory+'/'+string(cFileName)
                                    +#9#9+intToStr(nFileSizeLow)
                           +#9#9+intToStr(dwLowDateTime)
                                    +#9#9+intToStr(dwHighDateTime)
                                    +#9#9+formatDateTime('dd-mm-yy
hh:nn:ss',localFileTime);
                        memo1.Lines.add(s);
                        writeln(F,s);
                        application.ProcessMessages;
                    end;
             until not InternetFindNextFile(hDir, @pDirInfo);
             internetCloseHandle(hDir);
            end;
          end;

This works right except when a file is a new file (uploaded to the FTP
server at the last couple of hours). In this case the year is one year less
and the uour is one greatter (eg. if the original datetime is 25/5/2006
18:00:00 the result is 25/5/2005 19:00:00).
This stragne behaviour happens also with windows explorer and IE. Does'nt
happen with AceFTP or running a perl script at the server.
After a couple of hours the problem disappears !!!

Is something wrong with winInet functios or dateTime conversions ?
How is coded the dateTime in dwLowDateTime/dwHighDateTime ?

thanks in advance


PS. why idFTP.list returns no year for some files ?

Replies:

www.cryer.info
Managed Newsgroup Archive