在我FTP服务器的 tooling/1044/ 文件夹下有这样几个文件:
  1044E17A10t01_a.txt
  1044E17A10t01_b.txt
  1044E17A10t01_c.txt
  1044E17A10t01_d.txt
  1044E17A10t01_e.txt
我用 Internet Transfer控件想把它们从FTP上下载到本地电脑上,我是这样写的:Public sub Command1_click()
    Inet1.url=text1.text
    Inet1.execute,"CD tooling/1044/"
End SubPublic sub Command2_click()
   Inet1.Execute,"GET 1044E17A10T01_a.txt F:\1044E17A10T01_a.txt"
End Sub这样能下载成功!但是需两步,点两下,只能下载一个文件,我想点一下Command1就能把它们全都下载来.
Public sub Command1_click()
    Inet1.url=text1.text
    Inet1.execute,"CD tooling/1044/"
     Inet1.Execute,"GET 1044E17A10T01_a.txt F:\1044E17A10T01_a.txt"
End Sub
这样报警: 仍在执行上一个请求.我这样写
   Public sub Command1_click()
    Inet1.url=text1.text
    Inet1.execute,"CD tooling/1044/"
  select case state
     case  12
     Inet1.Execute,"GET 1044E17A10T01_a.txt F:\1044E17A10T01_a.txt"
    end select
End Sub
  点一下也能把文件下载下来,但到最后还是报警:与主机通讯时产生错误.还请各位大仙多多忙,感激不尽.谢谢...怎样才能把那几个文件批量下载呀.给点思路,或来个例子,谢谢各位

解决方案 »

  1.   

    参考这个
    Private Sub cmd(cmdstr As String)
        Do
            If Inet1.StillExecuting = False Then Exit Do
        Loop
        ExeStr = cmdstr
        Done = False
        Debug.Print ExeStr; "="
        Inet1.Execute , ExeStr
        Do
            DoEvents
            If Done Then Exit Do
        Loop
    End Sub
    Public Sub ReadAFile(fn As String)
        Inet1.URL = "ftp://"
        Inet1.UserName = "username"
        Inet1.Password = "password"    cmd "PWD"
        cmd "CD tooling/1044/"
        cmd "DIR"
        cmd "GET " + fn + " " + "F:\" + fn 
        cmd "QUIT"
    End SubPrivate Sub Command1_Click()
        Command1.Enabled = False
        ReadAFile "1044E17A10T01_a.txt"
        Command1.Enabled = True
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Dim intFile As Integer
    Dim vtData() As Byte
    Dim str As String
    'On Error GoTo ISCerr
        Debug.Print "State="; State,
        Select Case State
        Case 0
            Debug.Print "icNone"
        Case 1
            Debug.Print "icHostResolvingHost"
        Case 2
            Debug.Print "icHostResolved"
        Case 3
            Debug.Print "icConnecting"
        Case 4
            Debug.Print "icConnected"
        Case 5
            Debug.Print "icRequesting"
        Case 6
            Debug.Print "icRequestSent"
        Case 7
            Debug.Print "icReceivingResponse"
        Case 8
            Debug.Print "icResponseReceived"
            If Left(ExeStr, 2) = "CD" Then Done = True
        Case 9
            Debug.Print "icDisconnecting"
        Case 10
            Debug.Print "icDisconnected"
            Done = True
        Case 11
            Debug.Print "icError of [" + ExeStr + "]="; Inet1.ResponseInfo
            Done = True
        Case 12
            Debug.Print "icResponseCompleted----------------"
            Do
                str = Inet1.GetChunk(1024, icString)
                If LenB(str) = 0 Then Exit Do
                Debug.Print str
            Loop
            Done = True
        End Select
        Exit Sub
    ISCerr:
        Resume Next
    End Sub
      

  2.   

    你这个
      select case state 
        case  12 
        Inet1.Execute,"GET 1044E17A10T01_a.txt F:\1044E17A10T01_a.txt" 
        end select 需要写在这个事件里才行的吧,怎么跑到Command1_click里去啦
    Inet1_StateChanged(ByVal State As Integer)
      

  3.   

    在窗口里面加一个按钮Command1,再加一个MSINET.OCX控件Inet1
    我给的代码最前面加一句
    Dim Done As Boolean
    后放到代码窗口里面。
    设断点单步调试一下
      

  4.   

    Public Sub ReadAllFile()
        Inet1.URL = "ftp://你的FTP服务器地址"
        Inet1.UserName = "username"
        Inet1.Password = "password"
        cmd "CD tooling/1044/"
        cmd "GET 1044E17A10T01_a.txt F:\1044E17A10T01_a.txt"
        cmd "GET 1044E17A10T01_b.txt F:\1044E17A10T01_b.txt"
        cmd "GET 1044E17A10T01_c.txt F:\1044E17A10T01_c.txt"
        cmd "GET 1044E17A10T01_d.txt F:\1044E17A10T01_d.txt"
        cmd "GET 1044E17A10T01_e.txt F:\1044E17A10T01_e.txt"
        cmd "QUIT"
    End Sub
      

  5.   

    不行呀,,我怎么改,到这就是死循环...
    Do
            DoEvents
            If Done Then Exit Do
        Loop
      

  6.   

    Sorry!前面少加了一句。更正如下:
    在我给的代码最前面加一句
    Dim Done As Boolean
    Dim ExeStr As String后放到代码窗口里面。
    再试试。在VB6里面运行,看立即窗口里面显示的信息,其内容就和你直接用系统自带的FTP程序手动下载一样。
    实在不行就只能判断30秒超时放弃了。
    Private Sub cmd(cmdstr As String)
    dim after as double
        Do
            If Inet1.StillExecuting = False Then Exit Do
        Loop
        ExeStr = cmdstr
        Done = False
        Debug.Print ExeStr; "="
        Inet1.Execute , ExeStr
        after=Now+30#/24#/3600#
        Do
            DoEvents
            If Done Then Exit Do
            If Now>after Then
                MsgBox "cmd["+ExeStr+"] 30s overtime!"
            End If
        Loop
    End Sub
      

  7.   

    谢谢,我是这样写的.
       inet1.execute "GET 1044E17A10T01_a.txt F:\1044E17A10T01_a.txt"
         aaa=inet1.StillExecuting
      do while stillexecuting
          aaa=inet1.StillExecuting
       loop
     
      

  8.   

    Private Sub cmd(cmdstr As String)
    dim after as double
        Do
            If Inet1.StillExecuting = False Then Exit Do
        Loop
        ExeStr = cmdstr
        Done = False
        Debug.Print ExeStr; "="
        Inet1.Execute , ExeStr
        after=Now+30#/24#/3600#
        Do
            DoEvents
            If Done Then Exit Do
            If Now>after Then
                MsgBox "cmd["+ExeStr+"] 30s overtime!"
                Exit Do'应该加上这句
            End If
        Loop
    End Sub