TopPicLogo TopPicText

Закачка файла по URL (API)

'--------------------------------------------------------------------
' Module    : modDownloadURL
' Author    : es
' Date      : 06.05.2013
' Purpose   : Закачка файла по URL (API)
'--------------------------------------------------------------------
Private 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
'--------------------------------------------------------------------
Public Function URLDownLoadOneFile(sFileURL As String, sLocalFilePath As String) As Boolean
'es - 05.05.2013
'Так оно ещё и работает с кешем Браузера! :)
'--------------------------------------------------------------------
On Error GoTo URLDownLoadOneFile_Err
    URLDownLoadOneFile = URLDownloadToFile(0, sFileURL, sLocalFilePath, 0, 0) = 0
    
URLDownLoadOneFile_Bye:
    Exit Function

URLDownLoadOneFile_Err:
    'MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
    "in procedure TestDownLoadOneFile", vbCritical, "Error!"
    Resume URLDownLoadOneFile_Bye
End Function


Пример эксплуотации:

Private Sub URLDownLoadTest()
    Debug.Print URLDownLoadOneFile("http://msa.polarcom.ru/st/s0000061_Connection_Example_v01.zip", _
    "D:\temp\Connection_Example_v01.zip")
End Sub
Назад ToTop
L.E. 01.08.2016
Рейтинг@Mail.ru