怎样利用wininet.dll 获得网上文件大小。

qubolz 辽宁点速网络传播有限公司 部门经理/部门主管  2003-01-08 12:26:55
怎样利用wininet.dll 获得网上文件大小。
...全文
11 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ch111 2003-01-11
Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As Currency
ftLastAccessTime As Currency
ftLastWriteTime As Currency
nFileSizeHigh As Long
nFileSizeLow As Long '文件大小
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (ByRef lpdwError As Long, ByVal lpszErrorBuffer As String, ByRef lpdwErrorBufferLength As Long) As Boolean

Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long

Private Sub Form_Load()
Hopen = InternetOpen("ftp Get", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)


HConnection = 0
If HConnection <> 0 Then
InternetCloseHandle HConnection
End If
'INTERNET_INVALID_PORT_NUMBER 默认分配的端口号
HConnection = InternetConnect(Hopen,"ftp主机名", INTERNET_INVALID_PORT_NUMBER, sUser, sPassword, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
'INTERNET_FLAG_PASSIVE 被动模式
text1.text=GetFTPFileSize(sFile)

End Sub
'得到文件大小的函数,sFile为网上文件名
Private Function GetFTPFileSize(sFile As String) As Long
Dim szDir As String
Dim hFind As Long
Dim nLastError As Long
Dim pData As WIN32_FIND_DATA

hFind = FtpFindFirstFile(HConnection, sFile, pData, 0, 0)
If hFind = 0 Then
MsgBox "错误,不能完成升级", vbOKOnly, "错误"
End
Exit Function
End If

GetFTPFileSize = pData.nFileSizeLow
InternetCloseHandle (hFind)
End Function
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告