Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2006-04-30
Medium Priority
Last Modified: 2010-08-05
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.
Question by:RGuillermo
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16575179
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...

Accepted Solution

lostcarpark earned 2000 total points
ID: 16591821
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.

Author Comment

ID: 16601139
It does help me a lot Thank you very much!!

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Make the most of your online learning experience.
Six Sigma Control Plans
Starting up a Project

575 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