我一直在尝试使用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函数返回的文件。我做错了吗?
谢谢!
答案 0 :(得分:1)
".txt"
例程fileExtension$
SearchForFiles
"*."
"*..txt"
{{1}} {{1}} {{1}} {{1}}也许这会困扰你的计划?我不知道为什么“。”使用这种模式可以找到“......”,但是......