文档库 最新最全的文档下载
当前位置:文档库 › VB INET 获取文件列表

VB INET 获取文件列表

执行后就一直是“正在向主机发送请求”的状态
代码如下……
Private Sub Cmdlist_Click()
Inet1.RemoteHost = Txtftpip.Text
Inet1.RemotePort = Txtftpport.Text
Inet1.URL = "ftp://" & Trim(Txtftpip.Text)
https://www.wendangku.net/doc/377250270.html,erName = "Anonymous"
CurrentServerDir = "/"
If Inet1.StillExecuting Then
MsgBox "无法断开连接"
Exit Sub
End If
'列出服务器根目录
listserver
End Sub

'列出服务器指定目录下的文件和子目录
Private Sub listserver()
On Error GoTo ErrorH
If Not Inet1.StillExecuting Then
OperationStyle = 1
Inet1.Execute , "DIR"
End If
Exit Sub
ErrorH:
'
End Sub
Private Sub deallist(tempstr As String)
If Right(Trim(tempstr), 1) <> "/" Then
'表示接受到的是文件
addfiletolist (tempstr)
Else
'表示接受到的是目录
adddirtolist (tempstr)
End If
End Sub
'将文件名加入到列表视图中
Private Sub addfiletolist(tempstr As String)
Dim itmx As ListItem
Set itmx = ListView1.ListItems.Add(, , tempstr)
End Sub
'将目录加入到列表视图中
Private Sub adddirtolist(tempstr As String)
Dim itmx As ListItem
Set itmx = ListView1.ListItems.Add(, , tempstr)
End Sub

Private Sub Cmddownload_Click()
Winsock1.SendData fname
Text1.Text = Text1.Text & "成功下载……"
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case 0
Case 1
Text1.Text = Text1.Text & vbCrLf & "正在查询所指定的主机的IP地址"
Case 2
Text1.Text = Text1.Text & vbCrLf & "成功地找到所指定的主机的IP地址"
Case 3
Text1.Text = Text1.Text & vbCrLf & "正在与主机连接"
Case 4
Text1.Text = Text1.Text & vbCrLf & "已与主机连接成功"
Case 5
Text1.Text = Text1.Text & vbCrLf & "正在向主机发送请求"
Case 6
Text1.Text = Text1.Text & vbCrLf & "发送请求已成功"
Case 7
Text1.Text = Text1.Text & vbCrLf & "在接收主机的响应"
Case 8, 12
Select Case OperationStyle
Case 1
Text1.Text = Text1.Text & vbCrLf & "成功列出目录"
ListView1.ListItems.Clear
inetdata = Inet1.GetChunk(1024, 0)
If Trim(inetdata) <> 0 Then
temparray = Split(inetdata, vbCrLf, , vbTextCompare)
i = 0
Do While i < UBound(temparray)
If temparray(i) <> "" Then
deallist (temparray(i))
End If
i = i + 1
Loop
End If
Case 2
Text1.Text = Text1.Text & vbCrLf & "成功改变目录"
listserver
Case Else
End Select
End Select
Text1.SelLength = Len(Text1.Text)
End Sub

修改:
从上面代码看, OperationStyle变量没有

定义,所以出现上述问题。
其他代码不变,只对下面代码进行修改即可:
Case 12 ‘不要8
Select Case OperationStyle
Case 2
Text1.Text = Text1.Text & vbCrLf & "成功改变目录"
listserver
Case Else
Text1.Text = Text1.Text & vbCrLf & "成功列出目录"
ListView1.ListItems.Clear
inetdata = Inet1.GetChunk(1024, 0)
If Trim(inetdata) <> 0 Then
temparray = Split(inetdata, vbCrLf, , vbTextCompare)
i = 0
Do While i < UBound(temparray)
If temparray(i) <> "" Then
deallist (temparray(i))
End If
i = i + 1
Loop
End If
End Select
End Select
Text1.SelLength = Len(Text1.Text)
End Sub

相关文档