Prova così :D
Const scUserAgent = "API-Guide test program"
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://www.ublteam.com/Slayer/Comuni.rar"
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Const TotDW = 1024
Private Sub Command1_Click()
Dim nFreeFile As Integer
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail:
[email protected]
Dim sFileData As String
Dim lSize As Long
Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
'Create a buffer for the file we're going to download
sBuffer = Space(TotDW)
'Create an internet connection
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
'Open the url
hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
'Read the first 1024 bytes of the file
sFileData = ""
Do
InternetReadFile hFile, sBuffer, TotDW, Ret
'If Ret <> TotDW Then
sFileData = sFileData & Left$(sBuffer, Ret)
lSize = lSize + Ret
ProgressBar1.Value = lSize
'Else
'sFileData = sFileData & sBuffer
'End If
DoEvents
Loop Until Ret = 0
'clean up
InternetCloseHandle hFile
InternetCloseHandle hOpen
'scrittura del file
nFreeFile = FreeFile
Open "ciao.rar" For Output As #nFreeFile
Print #nFreeFile, sFileData
Close #nFreeFile
End Sub