'把指定给定一个网络文件(任何类型,可以是图像文件)的地址,然后用程序把其保存为本机器的文件 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
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
使用inet控件 Private Sub Command1_Click() Dim StrMsg As String Dim isbusy As Boolean
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
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
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
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
但是你没有使用INET控件啊?
请问你可以再给一个利用INET控件的例子吗?
我是需要HTTP下载,基于FTP的我已经知道了
谢谢
前两个不就是http的吗?
我现在是想用INET控件实现HTTP下载,还要可以指定保存路径及文件名
http://expert.csdn.net/Expert/TopicView1.asp?id=3045128
结贴~~