vb6 HOw to get the date and time of a folder in a FTP Server

HI Experts,
Please if you can teach me how to get the date and tima a directory was created in a FTP server?
Some VB6 code will be great.
RGuillermoProject ManagerAsked:
Who is Participating?
What are you using to connect to the FTP server?

The way I see it there are three approaches you could take:

1. Use a 3rd party FTP control. However you have to find a suitable control, and may have to buy it.

2. Roll your own using a TCP/IP control. Could be a lot of work, and you have to know a lot about the inner workings of the FTP protpcol.

3. Use the Windows FTP Shell command and capture the output.

Since the latter approach can (in theory) work with VB out of the box, it seems worth playing with, but it probably wouldn't be ideal for a really robust solution.

The first thing the program needs to do is set up a script to communicate with the FTP server:

    Dim iFile As Integer
    iFile = FreeFile()
    Open "c:\ftp.scp" For Output As #iFile
    Print #iFile, "open mywebserver.com"
    Print #iFile, "user"
    Print #iFile, "username" 'Insert Username here
    Print #iFile, "password" 'Insert password here
    Print #iFile, "cd /dir"
    Print #iFile, "ls -l"
    Print #iFile, "quit"
    Close #iFile

This is creating a file and writing the FTP commands to get the relevant information from the server. The CD command should navigate to the directory containing the directory you want to find out about.

The next section of the program executes the shell command. It needs to wait for the command to finish, so somewhere in the module declarations you need the following:

    Private Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Long) As Long

Then the code to execute the FTP command:

    Dim lModule As Long
    lModule = Shell(Environ("COMSPEC") & " /C ftp -n -s:c:\ftp.scp >c:\ftp.txt")
    Do While GetModuleUsage(lModule) > 0    'Wait for FTP command to finish.

Finally you need to parse the output file. The following code outputs the date of every file, so you'll need to pick out the file you want.

    Open "c:\ftp.txt" For Input As #iFile
    Do Until EOF(iFile)
        iDay = 0
        Input #iFile, sLine
        sMonth = Mid(sLine, 44, 3)
        sDay = Mid(sLine, 48, 2)
        If IsNumeric(sDay) Then
            iDay = Val(sDay)
        End If
        sYearTime = Mid(sLine, 51, 5)
        If InStr(sYearTime, ":") Then
            iYear = Year(Now)
            sTime = sYearTime
            iYear = Val(sYearTime)
            sTime = "00:00"
        End If
        sdate = iDay & "-" & sMonth & "-" & iYear & " " & sTime
        If IsDate(sdate) Then
            MsgBox sdate
            dtDate = CDate(sdate)
        End If

Hope this gets you on the right road.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I did not yet work with VB+FTP, but I guess I would do a "DIR" / "ls" in the parent folder and read the date/time information for the given folder...
RGuillermoProject ManagerAuthor Commented:
It does help me a lot Thank you very much!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.