?
Solved

how can i get the date of a file on a ftp server?

Posted on 2002-07-15
6
Medium Priority
?
158 Views
Last Modified: 2010-05-02
how can i get the date of a file on a ftp server?
0
Comment
Question by:Jambyte
[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
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:AlonHirsch
ID: 7156500
Hi,

When you send an 'ls' query to an FTP site - you get the file name, date and size returned.
simply parse the data returned from the command and pick the date from that.

You will have to experiment a bit first.

HTH,
Alon
0
 
LVL 4

Accepted Solution

by:
Glowman earned 400 total points
ID: 7156959
Public Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
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 Sub Download()
       
    Dim hOpen As Long
    Dim FileName(10) As String
    Dim FileSize(10) As Double
    Dim FileDate(10) As String
    Dim DownLoads(10) As String
    Dim DownloadDate(10) As String
    Dim DownloadSize(10) As String
    Dim TotalFiles As Integer
    Dim pData As WIN32_FIND_DATA
    Dim hFind As Long
    Dim nLastError As Long
    Dim x As Integer
    Dim y As Integer
    Dim bRet As Boolean
    Dim strDate As SYSTEMTIME
    Dim Holder
    Dim hFile As Long
   
    'Connect to the File Server
    hOpen = InternetOpen("ftp Generic", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
   
    hConnect = InternetConnect(hOpen, Url, 0, FtpId & "@" & ProxyId & "@" & Url, FtpPwd & "@" & ProxyPwd, 1, INTERNET_FLAG_PASSIVE, 0)
   
    If hConnect = 0 Then
        MsgBox "You were unable to connect to the Server : " & Url, vbCritical, "Internet Connection"
        Exit Sub
    End If
   
    'Enumerate the Directory putting values into the File* Array
    pData.cFileName = String(MAX_PATH, 0)
    hFind = FtpFindFirstFile(hConnect, "*.*", pData, 0, 0)
   
    If hFind = 0 Then
        If nLastError = ERROR_NO_MORE_FILES Then
            MsgBox "This directory is empty!", vbInformation, " Site is Empty"
            Exit Sub
        End If
    End If
   
    FileName(x) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    FileSize(x) = pData.nFileSizeLow
    Holder = FileTimeToSystemTime(pData.ftLastWriteTime, strDate)
    FileDate(x) = strDate.wMonth & "-" & strDate.wDay & "-" & strDate.wYear
   
    x = 1
   
    Do While x < 10
        pData.cFileName = String(MAX_PATH, 0)
        bRet = InternetFindNextFile(hFind, pData)
        If bRet = False Then
            nLastError = Err.LastDllError
            If nLastError = ERROR_NO_MORE_FILES Then
                Exit Do
            Else
                TotalFiles = x
                Exit Sub
            End If
        Else
            FileName(x) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
            FileSize(x) = pData.nFileSizeLow
            Holder = FileTimeToSystemTime(pData.ftLastWriteTime, strDate)
            FileDate(x) = strDate.wMonth & "-" & strDate.wDay & "-" & strDate.wYear
            x = x + 1
        End If
        DoEvents
    Loop
   
    'Close the handle
    CloseHandle (hFind)
   
    TotalFiles = x

End Sub


This is how I do it.  I have all of the Wininet function declarations if you need some more info.  Let me know if it helps or if you need more.

G
0
 
LVL 2

Author Comment

by:Jambyte
ID: 7158835
when i try to call the Download sub i get an error highlighting MAX_PATH and saying: Compile error: Constatnt Expression required
0
Independent Software Vendors: 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!

 
LVL 4

Expert Comment

by:Glowman
ID: 7160028
Jambyte,

There are a few constants and a couple declerations that you need as well.  I will try to list them all here.

'/////// Constants
Public Const MAX_PATH = 260
Public Const ERROR_NO_MORE_FILES = 18&
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_FLAG_PASSIVE = &H8000000

'////// Wininet.dll
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hOpen As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Public Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" (ByVal hFtpSession As Long, ByVal sFileName As String, ByVal lAccess As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, pBuffer As Byte, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

That should be about all you need.

G
0
 
LVL 2

Author Comment

by:Jambyte
ID: 7167090
when it saves the file it uses the clients date to stamp the file with. is there a way i can make it use the server's file date? i uped the points a little cuz this gets tricker
0
 
LVL 2

Author Comment

by:Jambyte
ID: 7167092
oops sorry this is the date checking code nevermind... and thank you!
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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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