怎样用vba(vb)开发开发ftp客户器端,例如怎样连接ftp服务器,怎样上传下载传文件,得到文件列表等

解决方案 »

  1.   

    Dim strDirectory As String
    Dim InetState As StringPrivate Sub Check1_Click()
    If Check1.Value = 1 Then
      Text2.Text = "anonymous"
      Text3.Text = "[email protected]"
    Else
      Text2.Text = ""
      Text3.Text = ""
    End If
    End SubPrivate Sub Command1_Click()
    Dim i As Integer, temp As String, strurl As String
    On Error GoTo Handle  strurl = Text1.Text
      Inet1.UserName = Text2.Text
      Inet1.Password = Text3.Text
       For i = 1 To 4 '´¦ÀíÊäÈëµÄURL
        temp = Mid(strurl, i, 1)
         If Asc(temp) <= Asc("z") And Asc(temp) >= Asc("a") Then
          strurl = Left(strurl, i - 1) + StrConv(temp, vbUpperCase) + Right(strurl, Len(strurl) - i)
         End If
       Next i
       If Left$(strurl, 6) = "FTP://" Then
        Inet1.Execute strurl
       Else
        Inet1.Execute "ftp://" & strurl
       End If
      Timer1.Enabled = True
    Handle:
    End SubPrivate Sub Command2_Click()
       Inet1.Cancel
       ListView1.ListItems.Clear
    End SubPrivate Sub Command3_Click()
      End
    End SubPrivate Sub Form_Load()
       ListView1.View = 0 '&Ecirc;&sup1;&Oacute;&Atilde;&acute;ó&Iacute;&frac14;±ê&cedil;&ntilde;&Ecirc;&frac12;
          
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
       InetState = State
       DoEvents
    End SubPrivate Sub Timer1_Timer()
      DoEvents
      '&frac14;à&Ecirc;&Oacute;&Aacute;&not;&frac12;&Oacute;×&acute;&Igrave;&not;
       If InetState = 12 Then
        Timer1.Enabled = False
        Dim iFile As Integer
        Dim strBuff As String
        
        strBuff = Inet1.GetChunk(1024)
        iFile = FreeFile()
        
        'Len1 = Len(strBuff)
        
        FillList (strBuff)
       
        End If
    End Sub
    Private Sub FillList(dirName As String)
     '&acute;&brvbar;&Agrave;í·&micro;&raquo;&Oslash;&micro;&Auml;&Auml;&iquest;&Acirc;&frac14;&ETH;&Aring;&Iuml;&cent;
     Dim i As Integer, i1 As Integer, i2 As Integer, j As Integer
     Dim nodexx As ListItem, ss As String, filen As String
     Dim TL As Boolean
     ListView1.ListItems.Clear
      i2 = 0
      
    1:
     i1 = Len(dirName)
     TL = False
     For i = 1 To i1
       ss = Mid(dirName, i, 1)
       aa = Asc(ss)
     If aa = 13 Then
     
      filen = Mid(dirName, 1, i - 1)
      If Len(filen) >= 1 Then
        i2 = i2 + 1
      For j = 1 To Len(filen)
        If Mid(filen, j, 1) = "/" Then
          TL = True
          filen = Mid(filen, 1, j - 1)
          Exit For
        End If
      Next j
       If TL Then
         Set nodexx = ListView1.ListItems.Add(i2, filen, filen, 1)
       Else
         Set nodexx = ListView1.ListItems.Add(i2, filen, filen, 2)
       End If
       ListView1.View = 0
       dirName = Mid(dirName, i + 2, i1 - i - 2)
       GoTo 1
       End If
     End If
    Next i
    End Sub
      

  2.   

    Dim bDowning As Boolean
    Dim lisNum As Integer
    Dim strTemp As String
    Private Sub cmdCd_Click()
    Dim strUrl As String
    Dim strfile As String
    strUrl = Combo1.Textstrfile = txtRemote.TextIf bDowning Then
    MsgBox "downing!"
    Exit Sub
    Else
    End IfbDowning = TrueInet1.Execute strUrl, "cd" + " " + strfile
    'Inet1.Execute strUrl, "PWD"'Inet1.Execute strUrl, "dir"'Inet1.Execute strUrl, "dir" + " " + strFilelblPath.Caption = strUrl + strfileEnd SubPrivate Sub cmdAdd_Click()
    Combo1.AddItem txtNewFTP.Text
    End SubPrivate Sub cmdDel_Click()
    Combo1.RemoveItem lisNum
    End SubPrivate Sub CmdDown_Click()
    On Error GoTo errhandle:
    Dim strUrl As String
    Dim sRFile As String
    Dim sLFile As StringIf bDowning Then
    MsgBox "downing!"
    Exit Sub
    Else
    End IfbDowning = True
    strUrl = Combo1.Text
    sRFile = txtRemote.Text
    sLFile = txtLocal.Text
    Inet1.Execute strUrl, "get " + txtRemote.Text + " " + sLFile
    Exit Sub
    errhandle:
        MsgBox Err.Description
    End SubPrivate Sub cmdExit_Click()
    Unload frmFtp
    End SubPrivate Sub cmdShow_Click()
    On Error GoTo errhandle:
    Dim strUrl As String
    Dim strfile As String
    strUrl = Combo1.Text
    strfile = txtRemote.TextIf bDowning Then
    MsgBox "downing!"
    Exit Sub
    Else
    End IfbDowning = TrueInet1.Execute strUrl, "dir " + strfile
    'Inet1.Execute strUrl, "dir"+lblPath.Caption = strUrl + strfile
    Exit Sub
    errhandle:
        MsgBox Err.Description
    End SubPrivate Sub cmdChoose_Click()
    'txtRemote.Text = txtRemote.Text + rtbShow.SelText
    Me.txtRemote.Text = Me.txtRemote.Text & strTemp
    strTemp = ""
    End SubPrivate Sub Command2_Click()
    Dim strUrl As String
    strUrl = Combo1.Text
     Inet1.Execute strUrl, "quit"End SubPrivate Sub Command3_Click()
    Dim strUrl As String
    Dim strfile As String
    strfile = txtRemote.TextstuUrl = Combo1.Text
    Inet1.Execute , " CDUP "
    End SubPrivate Sub Command1_Click()
    Inet1.Execute , "pwd"
    End SubPrivate Sub Form_Load()
    rtbShow.Text = ""
    Combo1.Text = "ftp://166.111.162.3/"
    lisNum = 0
    Combo1.AddItem "ftp://166.111.162.3/"
    Combo1.AddItem "ftp://166.111.4.80/"
    Combo1.AddItem "ftp://166.111.163.3/"
    Combo1.AddItem "ftp://ftp.lib.pku.edu.cn/"
    Combo1.AddItem "ftp://159.226.23.16/"
    bDowning = FalseEnd SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    FrmWebBroswer.Show
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Dim vPartData As VariantSelect Case State
    Case 1
        Me.StatusBar1.Panels(2).Text = "is looking"
    Case 2
        Me.StatusBar1.Panels(2).Text = "success finding "
          Me.StatusBar1.Panels(2).Text = "success finding "
    Case 3
      Me.StatusBar1.Panels(2).Text = "is connecting"
    Case 4
      Me.StatusBar1.Panels(2).Text = "success connected"
    Case 5
      Me.StatusBar1.Panels(2).Text = "is sending request"
    Case 6
      Me.StatusBar1.Panels(2).Text = "sucess sending"
    Case 7
      Me.StatusBar1.Panels(2).Text = "is receiving"
    Case 8
      Me.StatusBar1.Panels(2).Text = "success receive"Case 9
      Me.StatusBar1.Panels(2).Text = "is disconnecting"
    Case 10
      Me.StatusBar1.Panels(2).Text = "success disconnect"
    Case 11
      Me.StatusBar1.Panels(2).Text = "is error"Case icResponseCompleted
        rtbShow.Text = ""
          Me.StatusBar1.Panels(2).Text = "success receive data"
        rtbShow.Text = rtbShow.Text + vPartData
        vPartData = Inet1.GetChunk(1024, icString)
        Do While LenB(vPartData) > 0
            rtbShow.Text = rtbShow.Text + vPartData
          vPartData = Inet1.GetChunk(1024, icString)
          Loop
          rtbShow.Text = rtbShow.Text + vPartData
    rtbShow.SelStart = Len(rtbShow.Text)
    If bDowning Then
    MsgBox "down load file complete!"
    bDowning = False
    End If
    'Inet1.Execute , "quit"
    End Select
    End SubPrivate Sub Mnu_Click()End SubPrivate Sub MnuAdd_Click()
    cmdAdd_Click
    End SubPrivate Sub mnuDel_Click()
    cmdDel_Click
    End SubPrivate Sub mnuExit_Click()
    cmdExit_Click
    End SubPrivate Sub mnuList_Click()
    cmdShow_Click
    End SubPrivate Sub mnuLoad_Click()
    CmdDown_Click
    End SubPrivate Sub rtbShow_Click()
    Me.rtbShow.Span Chr(10), False, True
    Me.rtbShow.SelLength = Me.rtbShow.SelLength + 1
    'strTemp = Me.rtbShow.SelText
    Me.rtbShow.Span Chr(10), True, True
    Me.rtbShow.SelLength = Me.rtbShow.SelLength + 1
    strTemp = strTemp + Me.rtbShow.SelTextEnd SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)   Select Case Button.Key
       Case Is = "Connect"
         cmdShow_Click
       Case Is = "Add"
         cmdAdd_Click
         Case Is = "Delete"
         cmdDel_Click
         Case Is = "Save"
         CommonDialog1.ShowSave
         If Me.CommonDialog1.FileName = "" Then Exit Sub
         rtbShow.SaveFile (CommonDialog1.FileName)
         'cmdDown_Click
        Case Is = "Quit"
         ' cmdexit_click
       End SelectEnd SubPrivate Sub txtRemote_Change()
    txtLocal.Text = "e:\net\"End SubPrivate Sub combo1_Change()
    txtRemote.Text = ""
    lisNum = Combo1.ListIndexMe.StatusBar1.Panels(1).Text = Combo1.Text
    End Sub
      

  3.   

    请问 JKGF(放假) Inet1  是什么??
      

  4.   

    我下载了几个,ftp客户端软件,代码清楚,我已经连接上了服务器,了
      

  5.   

    Inet1:Microsoft Internet transfer control