Posts: 512
Threads: 106
Joined: Jul 2022
Reputation:
22
10-28-2023, 04:30 AM
(This post was last modified: 02-09-2026, 05:25 AM by eoredson.)
I have recently been using the following function to grab a file from the net:
Code: (Select All) Rem Program to grab file from url PD 2023.
Declare Dynamic Library "urlmon"
Function URLDownloadToFileA% (ByVal pCaller As Long, szURL As String, szFileName As String, Byval dwReserved As Long, Byval lpfnCB As Long)
End Declare
Declare Dynamic Library "kernel32"
Function GetLastError& ()
Function FormatMessageA& (ByVal f As Long, f$, Byval e As Long, Byval d As Long, g$, Byval s As Long, h$)
End Declare
Dim Shared ErrorBuffer As String * 260
Call GrabURL
End
' expiremental url grab.
Sub GrabURL
' URL to grab (page or a file)
URL$ = "http://www.applewoodbbs.linkpc.net/files/ifdc/oredson/ZAP12.ZIP"
' File to save URL as
URLfile$ = "ZAP12.ZIP"
' display files
Print "URL: "; URL$
Print "File: "; URLfile$
' Download it. Returns 0 if started.
a& = URLDownloadToFileA%(0, URL$ + Chr$(0), URLfile$ + Chr$(0), 0, 0)
If a& = 0& Then
Print "Download started."
End If
If a& > 0& Then
y& = FormatMessageA&(&H1200, "", a&, 0, ErrorBuffer$, 260, "")
Var1$ = "Error 0x" + Hex$(a&): Print Var1$
If y& > 2 Then
Var2$ = Left$(ErrorBuffer$, y& - 2): Print Var2$
End If
End If
End Sub
but what I want to know if there is a way to determine the progress of the download if it is a very large file!?
Thanks, Erik.
Posts: 273
Threads: 2
Joined: Apr 2022
Reputation:
58
You can get progress information by providing an implementation of the `IBindStatusCallback` interface to the `lpfnCB` parameter. This can't be done via QB64 alone though, you'd need to write some C++ code to implement the interface and then you could pass the progress information back to QB64.
That said, recent QB64-PE versions have native HTTP support which you could use in place of `URLDownloadToFile` and would allow you to display progress information. See Examples 2 and 4 on the Wiki page about it, they show examples of displaying the progress of the download as it is happening, and also downloading directly to a file (where you write to the file as you receive the data).
Posts: 512
Threads: 106
Joined: Jul 2022
Reputation:
22
10-28-2023, 04:51 AM
(This post was last modified: 10-28-2023, 05:06 AM by eoredson.)
Ok, thanks.
$Unstable:Http
have to be used?
Posts: 911
Threads: 38
Joined: Apr 2022
Reputation:
72
Check my programming corner for 3 download routines
The noticing will continue
Posts: 512
Threads: 106
Joined: Jul 2022
Reputation:
22
(10-28-2023, 12:06 PM)SpriggsySpriggs Wrote: Check my programming corner for 3 download routines
Where is your programming corner?
Posts: 1,098
Threads: 109
Joined: Apr 2022
Reputation:
102
(10-31-2023, 07:22 AM)eoredson Wrote: (10-28-2023, 12:06 PM)SpriggsySpriggs Wrote: Check my programming corner for 3 download routines
Where is your programming corner?
https://qb64phoenix.com/forum/forumdisplay.php?fid=30
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 512
Threads: 106
Joined: Jul 2022
Reputation:
22
11-01-2023, 05:44 AM
(This post was last modified: 11-01-2023, 06:53 AM by eoredson.)
Hmm.. A GrabUrl that actually works!?
Could you add Ctrl-V to paste url?
Thanks, Erik.
btw: when input as invalid url such as: splat.txt it throws multiple dialog error boxes..
Posts: 911
Threads: 38
Joined: Apr 2022
Reputation:
72
(11-01-2023, 05:44 AM)eoredson Wrote: Hmm.. A GrabUrl that actually works!?
Could you add Ctrl-V to paste url?
Thanks, Erik.
btw: when input as invalid url such as: splat.txt it throws multiple dialog error boxes.. The initial screen should be a console window, which allows for pasting. As far as the errors go, I did not do any error checking for invalid URLs because these are primarily examples for showing how to do it rather than finished products. You would have to write your own error handlers. But all three do work and work well, at least.
The noticing will continue
Posts: 512
Threads: 106
Joined: Jul 2022
Reputation:
22
02-13-2026, 03:03 AM
(This post was last modified: 02-13-2026, 03:40 AM by eoredson.)
Recently I got a program to get the status of a Url download from the .net
Code: (Select All) ' try to read info on url download. pd 2026.
Cls
URL$ = "http://www.applewoodbbs.linkpc.net/files/ifdc/oredson/SPHERE9.ZIP"
x = Download(URL$, outx)
End
Function Download (url As String, StatusCode As Long)
Dim bytes As Long, Length As Long
h& = _OpenClient(url)
StatusCode = _StatusCode(h&)
Locate 1, 1: Print "Status:"; StatusCode
Length = LOF(h&)
Locate 2, 1: Print "LOF:"; Length
While Not EOF(h&)
_Limit 60
Get #h&, , s$
bytes = bytes + Len(s$)
percent! = Int((bytes / Length) * 100!)
percent$ = Right$("000" + LTrim$(Str$(percent!)), 3) + "%"
Locate 3, 1: Print percent$;
Wend
Close #h&
End Function
Posts: 3,453
Threads: 376
Joined: Apr 2022
Reputation:
346
(02-13-2026, 03:03 AM)eoredson Wrote: Recently I got a program to get the status of a Url download from the .net
Code: (Select All) ' try to read info on url download. pd 2026.
Cls
URL$ = "http://www.applewoodbbs.linkpc.net/files/ifdc/oredson/SPHERE9.ZIP"
x = Download(URL$, outx)
End
Function Download (url As String, StatusCode As Long)
Dim bytes As Long, Length As Long
h& = _OpenClient(url)
StatusCode = _StatusCode(h&)
Locate 1, 1: Print "Status:"; StatusCode
Length = LOF(h&)
Locate 2, 1: Print "LOF:"; Length
While Not EOF(h&)
_Limit 60
Get #h&, , s$
bytes = bytes + Len(s$)
percent! = Int((bytes / Length) * 100!)
percent$ = Right$("000" + LTrim$(Str$(percent!)), 3) + "%"
Locate 3, 1: Print percent$;
Wend
Close #h&
End Function
You do realize there's an entire wiki page dedicated to downloading files, with multiple examples for various use cases?
https://qb64phoenix.com/qb64wiki/index.p...ding_Files
|