Vb6 搜寻及;使用wininet.dll api从FTP站点检索文件名

Vb6 搜寻及;使用wininet.dll api从FTP站点检索文件名,vb6,ftp,wininet,Vb6,Ftp,Wininet,我一直在尝试使用wininet.dll api搜索ftp站点以查找匹配的文件,但由于某些原因,它无法工作。 这是我一直使用的方法 Private Sub DoStuff() Dim hConnection As Long, hOpen As Long, sOrgPath As String, lRes As Long Dim scUserAgent$ scUserAgent$ = "vb wininet" hOpen = InternetOpen(scUse

我一直在尝试使用wininet.dll api搜索ftp站点以查找匹配的文件,但由于某些原因,它无法工作。 这是我一直使用的方法

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
这是SearchForFiles函数

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
对于从SearchForFiles函数返回的文件,我一直得到的是“.”和“.”。我做错什么了吗


谢谢

您为
SearchForFiles
例程提供的作为
文件扩展名$
参数的
“.txt”
“*”
模式连接在一起,产生
“*…txt”
。也许这就是困扰你的节目的原因?我真想知道为什么使用这种模式会找到“.”和“.”,不过…

修复我的代码!你试过什么?它在哪里断裂?你能跨过去吗?它不会断的。只是它从不读取FTP站点上/root/testdir/testdir2/目录下的匹配的.txt文件。下次提交vb代码时,请注意语法突出显示与撇号的注释不同。我冒昧地将所有注释
'comment
更改为
'/
,这更容易理解(也不会破坏您的代码),谢谢xtofl!下次我会记得的