+ -
当前位置:首页 → 问答吧 → vb FTP下载

vb FTP下载

时间:2011-08-30

来源:互联网

如何用VB从FTP下载文件并显示进度条

作者: mchyzh   发布时间: 2011-08-30

Inet控件
1、登录服务器
VB code

With Inet1
   .URL = "ftp://ftp.someFTPSite.com"
   .UserName = "你的用户名"
   .Password = "你的密码"
End With


2、Inet1.Execute方法执行ftp命令
VB code

Inet1.Execute "FTP://你的服务器", "GET 你的文件.txt"



3、StateChanged事件中接收数据,在该事件中更新进度条

VB code

Private Sub Inet1_StateChanged(ByVal State As Integer)
   Dim vtData As Variant '数据变量。
   Select Case State
   '...没有给出其它情况。
   Case icResponseCompleted '12
      '打开文件用于写入。
      Open txtOperation For Binary Access _
      Write As #intFile

      '得到第一个大块。注意:指定 Byte 数组
      ' (icByteArray) 以获取二进制文件。
      vtData = Inet1.GetChunk(1024, icString)

      Do While LenB(vtData) > 0
         Put #intFile, , vtData
         '得到下一大块。
         vtData = Inet1.GetChunk(1024, icString)
      Loop
      Put #intFile, , vtData
      '在这儿更新进度条
      Close #intFile
   End Select
End Sub

作者: c_cyd2008   发布时间: 2011-08-30