Private Function PutFtp(ByVal FileName As String, ByVal StrName As String) As Boolean
Dim StrU As String
    StrU = "put " & FileName & " " & StrName
    With Inet1
        .URL = "ftp://192.168.5.39"
        .UserName = "3gic"
        .Password = "3gic5.39"
        .Protocol = icFTP
        .RequestTimeout = 600
         Inet1.Execute , " " & StrU & " "
         
    End WithEnd Function
这是代码,出现问题比较奇怪,当直接执行的时候,报错“正在执行上一请求”
但是手动调试的时候就没有问题了

解决方案 »

  1.   

    1.获取Inet的状态。根据状态等上次执行完毕了才开始下一次执行。Inet应该有表示状态的属性吧?
    2.每次调用Inet时强行初始化Inet的状态。关闭上次的链接。
      

  2.   

    Dim ExeStr As String
    Dim Done As Boolean
    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
    Private 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