VB的FTP功能使用wininet.dll接口问题,求解

kings23 2011-11-18 08:20:13
在网上下载了一个CLSFTP的类,上传下载都没有问题,但是里面有个方法不知道该怎么用?
想实现的功能是:
进入FTP的目录,查询文件列表,如果文件名“20111118080024_***.***”比本地的最大文件名都大(字符对比),就下载;
然后定时刷新FTP目录循环下载,也可以对比文件的创建时间。

下面这个方法是调用wininet.dll的FtpFindFirstFile(m_hSession&, _FullDir$ & Filter$, WFD, _INTERNET_FLAG_RELOAD Or _INTERNET_FLAG_NO_CACHE_WRITE, 0&)方法,我定义了
Dim GetFileNames$(), GetFileSizes&()
Dim a As New clsftp
然后调用
j = a.GetDirListing(GetFileNames$(), GetFileSizes&())
后面就不知道该怎么用了,使用UBOUND(GETFILENAMES())都会显示错误,大家帮忙看下~
------------------------------------------------
Public Function GetDirListing&(FileNames$(), FileSizes&(), Optional ByVal SubDir$ = vbNullString)
On Local Error GoTo Handler

Dim WFD As WIN32_FIND_DATA
Dim Filter$
Dim hFind&, hFindConnect&
Dim FileSize&
Dim TempFileName$, TempFileSize&
Dim FullDir$
Dim i%

GetDirListing& = FAILURE&

Screen.MousePointer = vbHourglass

'Obtain the current FTP path
Filter$ = "*.*"

FullDir$ = m_Dir$ & SubDir$

AddRemFwdSlash FullDir$, 1

'If not connected, raise an error
If m_hSession& = NO_CONNECTION& Then
Err.Raise ERR_NOT_CONNECTED_TO_SITE, "clsFTP:PutFile", ERR_NO_CONNECTION$
End If

'Connection handles used by the FtpFindFirstFile
'API go out of scope once the files are
'listed, therefore it can not be reused.
'This restriction is handled by obtaining
'a fresh connection handle each time a call
'to FtpFindFirstFile is required, and releasing
'it once finished.
hFindConnect& = GetInternetConnectHandle()

hFind& = FtpFindFirstFile(m_hSession&, _
FullDir$ & Filter$, WFD, _
INTERNET_FLAG_RELOAD Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0&)

If hFind& Then
i% = 0
Do
ReDim Preserve FileNames$(i%)
ReDim Preserve FileSizes&(i%)
TempFileName$ = ClipNull(WFD.cFileName)
If Len(TempFileName$) Then
If WFD.dwFileAttributes And vbDirectory Then
TempFileName$ = TempFileName$ & FWDSLASH$
TempFileSize& = 0
Else
TempFileSize& = WFD.nFileSizeLow
End If
FileNames$(i%) = TempFileName$
FileSizes&(i%) = TempFileSize&
End If
'Continue while valid
i% = i% + 1
Loop While InternetFindNextFile(hFind&, WFD)

End If 'If hFind&

InternetCloseHandle hFindConnect&
InternetCloseHandle hFind&

Screen.MousePointer = vbDefault
GetDirListing& = SUCCESS&

ExitProc:
Exit Function

Handler:
GetDirListing& = Err.Number
Resume ExitProc

End Function
...全文
316 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kings23 2011-11-22
  • 打赏
  • 举报
回复
搞定 FTPFINDFIRSTFILE里面的第二个参数 必须为 *.*,不能加路径
kings23 2011-11-18
  • 打赏
  • 举报
回复
hFind& = FtpFindFirstFile(m_hSession&, _
FullDir$ & Filter$, WFD, _
INTERNET_FLAG_RELOAD Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0&)

这里老是找不到文件,导致 hFind&=0直接往下跳转~

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧