tags:

views:

116

answers:

1

Hi all,

I've been trying to use the wininet.dll api to search an ftp site for matching files but it's not working for some reason. Here's the method i've been using.

Private Sub DoStuff()
     Dim hConnection As Long, hOpen As Long, sOrgPath As String, lRes As Long
     Dim scUserAgent$

    scUserAgent$ = "vb wininet"
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    hConnection = InternetConnect(hOpen, mServer$, INTERNET_DEFAULT_FTP_PORT, mUserid$, mPassword$, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)

    ''//set the current directory to 'root/testdir/testdir2'
    FtpSetCurrentDirectory hConnection, "testdir/testdir2"

    ReDim matchingFiles$(1)
    Call SearchForFiles(hConnection, ".txt", matchingFiles$)


    ''//Close the connections
    InternetCloseHandle hConnection
    InternetCloseHandle hOpen
End Sub

Here is the SearchForFiles function

Public Sub SearchForFiles(hConnection As Long, fileExtension$, matchingFiles$())
    Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
    Dim i%

    ReDim matchingFiles$(1)

    i% = 1

    ''//create a buffer
    pData.cFileName = String(MAX_PATH, 0)
    ''//find the first file
    hFind = FtpFindFirstFile(hConnection, "*." + fileExtension$, pData, 0, 0)

    ''//if there is no file, then exit sub

    If hFind = 0 Then Exit Sub
    ''//show the filename

    matchingFiles$(i%) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)

    Do
        i% = i% + 1
        ''//create a buffer
        pData.cFileName = String(MAX_PATH, 0)
        ''//find the next file
        lRet = InternetFindNextFile(hFind, pData)
        ''//if there is no next file, exit do
        If lRet = 0 Then Exit Do
        ''//show the filename
        ReDim Preserve matchingFiles$(UBound(matchingFiles) + 1)
        matchingFiles$(i%) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)

    Loop
    ''//close the search handle
    InternetCloseHandle hFind
End Sub

All i keep getting is "." and ".." for the files being returned from the SearchForFiles function. Am i doing something incorrectly?

Thanks!

+1  A: 

The ".txt" you provide as fileExtension$ argument to the SearchForFiles routine is concatenated as is to the "*." pattern, yielding "*..txt". Maybe that's what bothers your program? I do wonder why "." and ".." are found using this pattern, though...

xtofl
ah i missed that thanks!
zSysop