问题描述:
    需要做一个配置ftp服务器的程序,配置的内容包括:IP,用户名,密码,端口号。在保存配置前,需要对所填的配置信息进行测试,以确定所填用户名及密码是否可以成功连上FTP服务器。
该功能如何实现?------
我所做的尝试:
  利用inet控件,设置其URL,User,Passwd 及端口属性
    然后用OpenURL的方法:call inet1.OpenURL (.URL)
    再通过判断state的返回值,以确定是否成功。返回值为1,表示成功。
但是,不管我输的用户名或密码对不对,state的返回值都是1,晕,郁闷哦!!!!!
各位大虾帮帮小弟吧,有何高见,敬请赐教!

解决方案 »

  1.   

    Private Sub Inet1_StateChanged(ByVal State As Integer)    Select Case State
            Case 4 
                  MsgBox "ok"
            Case 12
            Case Else
        End Select
    End Sub
      

  2.   

    Option Explicit
    Dim strOper As StringPrivate Sub Command1_Click()
        On Error GoTo ConError
        Command1.Enabled = False    With Inet1
            .URL = txFTP(0).Text
            .Protocol = icFTP
            .UserName = txFTP(2).Text
            .Password = txFTP(3).Text
        End With    strOper = "Dir"
        Inet1.Execute , strOper
        Exit SubConError:
        MsgBox "无法与" & txFTP(0).Text & " 网站取得连接! "
    End SubPrivate Sub Command2_Click()
        strOper = "GetFile"
        Inet1.Execute , "Get " & txFTP(1).Text & " " & App.Path & "\" & txFTP(1).Text
    End SubPrivate Sub Command3_Click()
        Inet1.Execute , "Quit"
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
        Select Case State
            Case 4
                Command2.Enabled = True
                Command3.Enabled = True
                txFTP(0).Enabled = False
                txFTP(1).Enabled = True
                txFTP(2).Enabled = False
                txFTP(3).Enabled = False
            Case 11
                If InStr(Inet1.ResponseInfo, "No such file") > 0 Or _
                    InStr(Inet1.ResponseInfo, "No such file or directory") Then
                    MsgBox "符合的文件下载!"
                Else
                    MsgBox Inet1.ResponseInfo
                End If
            Case 10
                Command1.Enabled = True
                Command2.Enabled = False
                Command3.Enabled = False
                txFTP(0).Enabled = True
                txFTP(1).Enabled = False
                txFTP(2).Enabled = True
                txFTP(3).Enabled = True
            Case 12
                If LCase(strOper) = "dir" Then
                    InetGetDir
                    MsgBox "已经与主机连接 !"
                Else
                    MsgBox "文件下载成功!"
                End If
        End Select
        Debug.Print 状态常数:" & State & "信息内容:" & Inet1.ResponseInfo
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        Inet1.Cancel
    End SubPrivate Sub InetGetDir()
        'vtData 的数量类型为 Variant
        Dim vtData
             '将接收的文件以二进制的方式打开文件输出
            Open App.Path & "\" & txFTP(1).Text & ".txt" For Binary Access Write As #1
                  
           vtData = Inet1.GetChunk(1024, icString)
            Do While LenB(vtData) > 0
                Put #1, , vtData
                vtData = Inet1.GetChunk(1024, icString)
            Loop
            Put #1, , vtData
            Close #1
    End Sub
    ------------------------------------------
    说明:
    cmd1:与FTP主机连接
    cmd2:开始下载
    cmd3:终止连接
      

  3.   

    扫描一下对方端口(缺省:21)开了没有。(其实就是尝试连接一下该端口,成功说明FTP服务开了)
      

  4.   

    楼主可以用下面的代码试验一下:
    Private Sub Inet1_StateChanged(ByVal State As Integer)
      debug.print state
    end sub
    可以看到state的变化过程,而不是像楼主说的那样是一个值。