张继科和马龙结婚:vb中怎么应用ftp

来源:百度文库 编辑:中科新闻网 时间:2024/05/06 05:14:14
在VB中怎么应用ftp

对于FTP,你可以使用Execute方法执行FTP命令SIZE获得文件大小。然后在StateChanged事件中可以获得返回的文件大小。
Private Sub Command1_Click()
Inet1.Execute "ftp://127.0.0.1", "SIZE 1.gif"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
'State = 12 时,用 GetChunk 方法检索服务器的响应。

Dim vtData As Variant ' Data variable.
Select Case State
'...没有列举其它情况。
Case icError '11
'出现错误时,返回 ResponseCode 和 ResponseInfo。
vtData = Inet1.ResponseCode & ":" & _
Inet1.ResponseInfo
Case icResponseCompleted ' 12

Dim strData As String
Dim bDone As Boolean: bDone = False

'取得第一个块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents

Do While Not bDone
strData = strData & vtData
'取得下一个块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents

If Len(vtData) = 0 Then
bDone = True
End If
Loop
MsgBox strData
End Select

End Sub

对于HTTP下载,你可以用GetHeader(Content-length)来获得文件大小。但不是所有HTTP下载时都能获得文件长度,特别是通过代理服务器下载文件时。如:
Private Sub Form_Load()
Inet1.Execute "http://askpro.yeah.net/"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
If State = icResponseReceived Then
MsgBox "File size is " & Inet1.GetHeader("Content-Length")
End If
End Sub