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

Posted on 2006-04-30
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 142

    Expert Comment

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

    Accepted Solution

    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"
        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

    It does help me a lot Thank you very much!!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now