Page 1 of 2

How to get Date and Time with oFTP

Posted: Sat Nov 04, 2006 11:06 am
by John
Hi,

i'm using oFTP:Directory("*.*"), but it seems it only returns the name and file size. Is there any way to also retrieve the file's date and time?

Thanks,

John.

Posted: Fri Nov 10, 2006 7:30 am
by Antonio Linares
John,

Please modify Class TFtp Method Directory this way:

Code: Select all

...
      if ! Empty( oWin32FindData:cFileName )
         AAdd( aFiles, { oWin32FindData:cFileName,;
                         oWin32FindData:nSizeLow,;
                         oWin32FindData:nLastWriteAccess,;
                         oWin32FindData:nCreationTime } )
         while InternetFindNextFile( hFTPDir, @cBuffer )
            oWin32FindData:cBuffer = cBuffer
            AAdd( aFiles, { oWin32FindData:cFileName,;
                            oWin32FindData:nSizeLow,;
                            oWin32FindData:nLastWriteAccess,;
                            oWin32FindData:nCreationTime } )
         end
      endif
...

Posted: Fri Nov 10, 2006 8:30 am
by John
Hi Antonio,

thanks for the reply. It seems i only get the time returned in this case?

Regards,

John.

Posted: Fri Nov 10, 2006 9:27 am
by Antonio Linares
John,

What value do you get for oWin32FindData:nLastWriteAccess ?

Posted: Sat Nov 11, 2006 8:46 am
by John
Hi Antonio,

i probably did something wrong because i get only empty strings returned for the date and time:

aFtpList:=oFTP:Directory("*.*")
ShowArr(aFtpList)

Function ShowArr(aDirList)
aEval(aDirList,{|i,t| iif(Valtype(i)=="A",(ShowArr(i)),(msgalert(i)) ) })
Return (.t.)

Any suggestions?

Regards,

John.

Posted: Sat Nov 11, 2006 9:23 am
by Antonio Linares
John,

Please try this:

aFtpList:=oFTP:Directory("*.*")
MsgInfo( Len( aFtpList[ 1 ][ 3 ] ) )

and let me know what you get, thanks

Posted: Sat Nov 11, 2006 3:25 pm
by John
Antonio,

it returns an 8, but i can't relate that to a file present...

Regards,

John.

Posted: Mon Nov 13, 2006 7:24 am
by Antonio Linares
John,

It looks like there is something different from a number there.
Please try this:

Code: Select all

aFtpList:=oFTP:Directory("*.*") 
for n = 1 to Len( aFtpList[ 1 ][ 3 ] )
   MsgInfo( Asc( SubStr( aFtpList[ 1 ][ 3 ], n, 1 ) ) )
next
and let me know what you get, thanks

Posted: Thu Nov 16, 2006 6:22 pm
by John
Hi Antonio,

the following files are present in the ftp directory:
Image

I get the following results:
0, 46, 46, 201, 78, 240, 198, 1

Best regards,

John.

Posted: Thu Nov 16, 2006 6:34 pm
by Antonio Linares
John,

Please copy here the values that you get for each of the four items that you have in the directory, thanks.

Posted: Fri Nov 17, 2006 7:26 am
by Antonio Linares
John,

Code: Select all

aFtpList:=oFTP:Directory("*.*")
for m = 1 to Len( aFtpList )
   for n = 1 to Len( aFtpList[ m ][ 3 ] )
      MsgInfo( Asc( SubStr( aFtpList[ m ][ 3 ], n, 1 ) ) )
   next
next
so we can see the eight bytes for each file.

Posted: Sat Nov 18, 2006 5:24 am
by John
Antonio,

the values are:
0, 46, 46, 201, 78, 240, 198, 1, 0, 232, 33, 111, 190, 255, 198, 1, 0, 46, 46, 201, 78, 240, 198, 1, 0, 46, 46, 201, 78, 240, 198, 1.

Saludos,

John.

Posted: Sat Nov 18, 2006 7:40 am
by Antonio Linares
John,

It looks as three files have the same date:

0, 46, 46, 201, 78, 240, 198, 1
0, 46, 46, 201, 78, 240, 198, 1
0, 46, 46, 201, 78, 240, 198, 1
0, 232, 33, 111, 190, 255, 198, 1

From the image that you provided, three have the same date too:

15-10-2006
15-10-2006
15-10-2006
4-11-2006

Now we need to find in what data format the dates are stored.

Posted: Sat Nov 18, 2006 8:06 am
by Antonio Linares
The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.

typedef struct _FILETIME { // ft
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;

Lets see how to get a Clipper date and time from that :-)

Posted: Sat Nov 18, 2006 8:22 am
by Antonio Linares
This is the API function to use:

The FileTimeToSystemTime function converts a 64-bit file time to system time format.

BOOL FileTimeToSystemTime(

CONST FILETIME *lpFileTime, // pointer to file time to convert
LPSYSTEMTIME lpSystemTime // pointer to structure to receive system time
);