我现在使用VB自带的INET控件进行OPENURL操作,可以得到服务器端某文件的内容,如http://abc.com/a.txt但是我现在怎么才能把a.txt 下载到本地呢?并且要能指定保存的路径和文件名
如我想把http://abc.com/a.txt 下载到本地并保存为E:\a.txt呢?急啊。

解决方案 »

  1.   

    '把指定给定一个网络文件(任何类型,可以是图像文件)的地址,然后用程序把其保存为本机器的文件
    Public Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long'保存网上的图片到硬盘
    'URL是图版的网址
    'LocalFilename 是保存到本地的文件名及目录
    '使用例子:DownloadFile "http://www.21cn.com/aa.jpg","c:\aa.jpg"Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
        Dim lngRetVal As Long
        lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
        If lngRetVal = 0 Then DownloadFile = True
    End Function
      

  2.   

    Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
    Private Sub Command1_Click()
       
       Dim sDownload As String   sDownload = StrConv(Text1.Text, vbUnicode)
        DoFileDownload (sDownload)End SubPrivate Sub Form_Load()
    Text1.Text = "http://services2k.jflinc.com/stevex/mapx/mapx-v11.zip"
    Form1.Caption = "Audiograbber 1.62 Full"
    Text2.Text = "http://www6.50megs.com/audiograbber/demos/cr-ag161.zip"
    End Sub
      

  3.   

    使用inet控件
    Private Sub Command1_Click()
      Dim StrMsg As String
      Dim isbusy As Boolean
      
      Inet1.URL = "ftp://www.ourfly.com/"
      Inet1.Protocol = icFTP
      Inet1.UserName = "ouly"
      Inet1.Password = "ou950868"
      
      StrMsg = "Dir"
      Inet1.Execute , StrMsg
      
    End SubPrivate Sub Command2_Click()
    On Error GoTo errhandle:
    Dim s1 As String
      
      Inet1.Execute , "Get 2.zip C:\234.zip"
      Do While isbusy
           isbusy = Inet1.StillExecuting
           DoEvents
      Loop
    errhandle:
        MsgBox Err.Description
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
     Case 1
        Text1.Text = "is looking"
    Case 2
        Text1.Text = "success finding "
    Case 3
      Text1.Text = "is connecting"
    Case 4
      Text1.Text = "success connected"
    Case 5
      Text1.Text = "is sending request"
    Case 6
      Text1.Text = "sucess sending"
    Case 7
      Text1.Text = "is receiving"
    Case 8
      Text1.Text = "success receive"
    Case 9
      Text1.Text = "is disconnecting"
    Case 10
      Text1.Text = "success disconnect"
    Case 11
      Text1.Text = "is error"
    Case 12 'icResponseCompleted
      Text1.Text = "success receive data"
      bDowning = False
    End Select
    End Sub
      

  4.   

    呵呵,满好满好,调试通过
    但是你没有使用INET控件啊?
    请问你可以再给一个利用INET控件的例子吗?
      

  5.   

    online(龙卷风V2.0--再战江湖)
    我是需要HTTP下载,基于FTP的我已经知道了
    谢谢
      

  6.   

    第三个不就是inet的吗?
    前两个不就是http的吗?
      

  7.   

    前两个我已经试过了,可以的
    我现在是想用INET控件实现HTTP下载,还要可以指定保存路径及文件名
      

  8.   

    看这个帖子中我的回复
    http://expert.csdn.net/Expert/TopicView1.asp?id=3045128
      

  9.   

    非常感谢online(龙卷风V2.0--再战江湖),以及 griefforyou(为你伤心)
    结贴~~