File Date/Time from Unix ftp Server 
Author Message
 File Date/Time from Unix ftp Server

Hi

I'm using the ftpfindfirstfile api to return file information from an
ftp server running in unix.  The problem is that I need to get the
file's last accessed date... and because unix doesn't store dates in
Coordinated Universal Time, it won't read it... I get 0 back for the
date values.  Does anyone know of a way that this can be handled?

TIA,

Kathy



Mon, 12 Apr 2004 00:00:12 GMT  
 File Date/Time from Unix ftp Server

Quote:

> I'm using the ftpfindfirstfile api to return file information from an
> ftp server running in unix.  The problem is that I need to get the
> file's last accessed date... and because unix doesn't store dates in
> Coordinated Universal Time, it won't read it... I get 0 back for the
> date values.  Does anyone know of a way that this can be handled?

Unix stores timestamps as a count of seconds past midnight 1/1/70 GMT,
but ftpfindfirstfile uses a Win32 FILETIME structure.

Public Type FILETIME
  dwLowDateTime As Long
  dwHighDateTime As Long
End Type

Public Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer
  wDay As Integer
  wHour As Integer
  wMinute As Integer
  wSecond As Integer
  wMilliseconds As Integer
End Type

Public Declare Function FileTimeToLocalFileTime Lib "Kernel32" ( _
  lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long

Public Declare Function FileTimeToSystemTime Lib "Kernel32" ( _
  lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long

' why oh why don't DateAdd, DateSerial, or TimeSerial take Doubles?
' or maybe "ss" for milliseconds and "ssss" for nanoseconds?
Private Function FileTimeToDate(UTC As FILETIME, ByVal LeaveAsUTC As Boolean) As Date
  Const ToST = "FileTimeToSystemTime"
  Const ToLT = "FileTimeToLocalFileTime"

  If UTC.dwHighDateTime = 0 And UTC.dwLowDateTime = 0 Then
    'FileTimeToDate = Empty
    Exit Function
  End If

  Dim ST As SYSTEMTIME, LT As FILETIME

  If LeaveAsUTC Then
    If 0& = FileTimeToSystemTime(UTC, ST) Then
      Err.Raise vbObjectError + Err.LastDllError, , ToST
    End If
  Else
    If 0& = FileTimeToLocalFileTime(UTC, LT) Then
      Err.Raise vbObjectError + Err.LastDllError, , ToLT
    End If
    If 0& = FileTimeToSystemTime(LT, ST) Then
      Err.Raise vbObjectError + Err.LastDllError, , ToST
    End If
  End If
  FileTimeToDate = DateAdd("s", ST.wHour * 3600# + ST.wMinute * 60# + ST.wSecond _
    + ST.wMilliseconds / 1000#, DateSerial(ST.wYear, ST.wMonth, ST.wDay))
End Function

' experimental section depends on FILEDATETIME being unsigned 64-bit
' hundreds of nanoseconds past midnight 1/1/1601 and on VBA's Date
' being constant intervals of anything either before or after anytime
Private Function FileTimeToDateEx(UTC As FILETIME, ByVal LeaveAsUTC As Boolean) As Date
  Const ToLT = "FileTimeToLocalFileTime"

  If UTC.dwHighDateTime = 0 And UTC.dwLowDateTime = 0 Then
    'FileTimeToDateEx = Empty
    Exit Function
  End If

  Dim LT As FILETIME

  If LeaveAsUTC Then
    LT = UTC
  ElseIf 0& = FileTimeToLocalFileTime(UTC, LT) Then
    Err.Raise vbObjectError + Err.LastDllError, , ToLT
  End If

  Const Epoch = #1/1/1601#
  Const ToDate = 0.0000001 * (#1/1/00# - #12/31/99#) / 24# / 3600#
  Const Bit32 = 2# ^ 32#
  Dim D As Date
  If LT.dwHighDateTime < 0& Then
    D = (Bit32 + LT.dwHighDateTime) * Bit32 * ToDate + Epoch
  Else
    D = LT.dwHighDateTime * Bit32 * ToDate + Epoch
  End If
  If LT.dwLowDateTime < 0& Then
    FileTimeToDateEx = (Bit32 + LT.dwLowDateTime) * ToDate + D
  Else
    FileTimeToDateEx = LT.dwLowDateTime * ToDate + D
  End If
End Function

--
Joe Foster <mailto:jlfoster%40znet.com>  Sign the Check! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Mon, 12 Apr 2004 02:29:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. FTP - Upload files from PC to UNIX server

2. How to get date and time from unix time in VB

3. Unix time to VB date/time conversion?

4. Getting File Date/Time via FTP

5. FTP to an Unix server

6. Comparison Of FTP File Time With Local File Time Fails

7. FTP - Get File Date from FTP Site

8. 0 KB file created when ftp'd from Unix

9. FTP text file from Windows to Unix Host

10. How To FTP a File To FTP Server

11. Compare date in form with date/time in form with date/time in database

12. Problem Using Time Part of a Date-Time field in SQL-Server

 

 
Powered by phpBB® Forum Software