sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
I'm borrowing these two code from another user on here.
I'm trying to download some smaller files (not overly big) via a very slow to slow satellite connection (wx dependent). The first code (FileAPI) through a "Download File Process Failed" and the second code broke at "WinHttpReq.send"
Latency 626ms
download .35-.76mb/s
upload bursts of 2.5mb/s
Any ideas why or is there a better way to do this?
Code to be modified once it works on this first link....
Thanks!
I'm trying to download some smaller files (not overly big) via a very slow to slow satellite connection (wx dependent). The first code (FileAPI) through a "Download File Process Failed" and the second code broke at "WinHttpReq.send"
Latency 626ms
download .35-.76mb/s
upload bursts of 2.5mb/s
Any ideas why or is there a better way to do this?
Code to be modified once it works on this first link....
Thanks!
Code:
Option ExplicitDeclare PtrSafe 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
Sub DownloadFileAPI()
Dim strURL As String
Dim LocalFilePath As String
Dim DownloadStatus As Long
strURL = "https://nauticalcharts.noaa.gov/publications/coast-pilot/files/cp1/CPB1_WEB.pdf"
LocalFilePath = "C:\Users\bridge\Desktop"
DownloadStatus = URLDownloadToFile(0, strURL, LocalFilePath, 0, 0)
If DownloadStatus = 0 Then
MsgBox "File Downloaded. Check in this path: " & LocalFilePath
Else
MsgBox "Download File Process Failed"
End If
End Sub
Sub DownloadFile()
Dim WinHttpReq As Object
Dim oStream As Object
Dim myURL As String
Dim LocalFilePath As String
myURL = "https://nauticalcharts.noaa.gov/publications/coast-pilot/files/cp1/CPB1_WEB.pdf"
LocalFilePath = "C:\Users\bridge\Desktop"
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "", "" '("username", "password")
WinHttpReq.send
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile LocalFilePath, 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If
End Sub
Last edited: