Link to home
Start Free TrialLog in
Avatar of drydo
drydo

asked on

Unusual behaviour reading FILETIME attributes using FTP

Hi Guys,

Long time reader, first time poster.

I have a rather unusual problem reading the FILETIME attributes of a file using an FTP connection (called using the wininet.dll functions).

For an utterly bizarre reason, if I FTP a file on a remote server (either using CLI FTP or BulletProof FTP) and then read and convert the FILETIME attributes of the file into a SYSTEMTIME, it is ALWAYS one year out?!?

But if I view the file using a FTP Client (e.g. BulletProof) it shows the correct date.

Even more unusual is that after one hour exactly (yes, I timed it) if I read the file again it provides the correct date?!?

For example, the following debug print shows the directory structure on the remote server but it shows the file 'main.exe' with the date/time of '09/09/01 10:53', which is correct apart from the fact it is a year out...

Filename: main.exe Date: 09/09/2001 Time: 10:53
Filename: new_BMN_Manager.exe Date: 06/09/2002 Time: 17:13
Filename: new_config.txt Date: 06/09/2002 Time: 17:13
Filename: new_debug.txt Date: 06/09/2002 Time: 17:13
Filename: new_pho1.jpg Date: 06/09/2002 Time: 17:13
Filename: new_pho2.jpg Date: 06/09/2002 Time: 17:13
Filename: new_pho3.jpg Date: 06/09/2002 Time: 17:13
Filename: new_pho4.jpg Date: 06/09/2002 Time: 17:13
Filename: new_pho5.jpg Date: 06/09/2002 Time: 17:13

...however, if run the same code an hour after the file has been uploaded (11.53) the debug results are...

Filename: main.exe Date: 09/09/2002 Time: 10:53
Filename: new_BMN_Manager.exe Date: 06/09/2002 Time: 17:13
Filename: new_config.txt Date: 06/09/2002 Time: 17:13
Filename: new_debug.txt Date: 06/09/2002 Time: 17:13
Filename: new_pho1.jpg Date: 06/09/2002 Time: 17:13
Filename: new_pho2.jpg Date: 06/09/2002 Time: 17:13
Filename: new_pho3.jpg Date: 06/09/2002 Time: 17:13

...and yes, this time it is showing the correct year.

I must admit I'm utterly baffled on this, is there some kind of caching I'm not aware of.  What is Bulletproof FTP doing that I'm not.

Anyway, thanks for reading this and if you can be of any help I will be extremely grateful.

Cheers

Drydo


Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Strange thing.
How do you fetch file on server?
How do you translate Filetime struct to local time ?
Avatar of drydo
drydo

ASKER

Hi Richie,

Nice to know there is someone out there!

Anyway, I'm retreiving the file using 'InternetFindNextFile' call to the Wininet.dll and obtaining the 'ftLastWriteTime' attribute from the WIN32_FIND_DATA struct thing.

In respect to translating the FILETIME value I'm using a function to convert it from a FILETIME to a SYSTEMTIME, as below...

' Converts the FILETIME value to a system time date
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, _
    lpSystemTime As SYSTEMTIME) As Long



Private Function GetFileDateString(CT As FILETIME) As String

Dim ST As SYSTEMTIME
Dim sngDate As Single, sngTime As Single
   
If FileTimeToSystemTime(CT, ST) Then
    sngDate = DateSerial(ST.wYear, ST.wMonth, ST.wDay)
    sngTime = TimeSerial(ST.wHour, ST.wMinute, ST.wSecond)
    ' And return the value
    GetFileDateString = Format$(sngDate, DATE_FORMAT) & STR_DELIMITER & Format$(sngTime, TIME_FORMAT)
Else
    ' Else return a null
    GetFileDateString = ""
End If
End Function


And that's about it.  Let me know if you fancy a copy of the source code or (even better) let me know whether you've done something similar.

Cheers

Drydo
Yes, i did some similer (i have a class to do FTP Stuff)
The problem that raised to me was with 'ftLastAccessTime' since findfile... "touches" the file that is listing, but not with 'ftLastWriteTime' member.
Avatar of drydo

ASKER

Hi Richie,

Thanx for your response and its good to know that someone else has suffered with this.

Anyway, did you manage to resolve it?  Or to put it another way, how did you access the 'ftLastWriteTime' member.

Cheers

Drydo
Avatar of drydo

ASKER

Hi Richie,

Thanx for your response and its good to know that someone else has suffered with this.

Anyway, did you manage to resolve it?  Or to put it another way, how did you access the 'ftLastWriteTime' member.

Cheers

Drydo
Avatar of drydo

ASKER

Best give you an update.

I've basically haven't been able to suss why the above problem is occuring, I've tried a number of different things - I've even downloaded some official Microsoft FTP code with a 'FileTimeToSystemTime' call in it - and that follows the behaiour as above.

Anyway, the solution I'm probably going to use will be a fudge, if the time read from the server is the same day and month as the local time (on the client) and within the hour of the upload, then I'll increment the year to give an *assumed* true value.

Not brilliant, but it will work.  Out of interest for anyone reading this, I was using Windows 98 SE.

Finally, a big thank you to Richie for his correspondence.

Drydo
Dangerous.
The problem is that i can't reproduce the error with that struct member and work with it.
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi drydo,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.

drydo, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
Avatar of drydo

ASKER

DanRollins:

[For some bizarre reason - I didn't receive a notification that anybody had replied to this question!]

Anyway, I sussed out the problem (last week actually) - it turns out the time being received was a UDT date which was being adjusted by the FileTimeToSystemTime function to the appropriate timezone hour adjustment!!!

So if I set my computer to be in a weird and wonderful timezone, e.g. 8 hours ahead.  The time being returned would be eight hours ahead for eight hours - as soon as that time elapsed it reverted to the true value.

Bizarre huh.
Ah!  A puzzle wrapped in an mystery wrapped in an engima... what could be more enjoyable?
<Dan FacialExpresssion= ";-)" />