Just a simple demonstration of the AsyncDownload-Feature, any VB-Usercontrol has already built-in.
It supports http- and ftp-downloads for files up to 2GB.
What's perhaps interesting from a Control-Design-point, is the organization of the whole thing.
There's a Host-Control: ucAsyncDLHost which only ensures Scrolling and Event-Delegation of the
separate Download-Entries it manages and visualizes.
The AsyncDownload itself is performed within another (Child-)Control: ucAsyncDLStripe,
which is a windowless-Control (containing a simple Progress-Bar and a simple Stop/Resume-Button).
So, those windowless-"Stripe-entries" make up the "Rows" within the outer ucAsyncDLHost Control.
Here's the usual Screenshot and the Download-Link:
Re: VB6 Simple Async-Download-Ctl for multiple Files
Hi,
I receive
Procedure declaration does not match description of event or procedure having same name
on this line
vb Code:
Private Sub ucAsyncDLHost_DownloadComplete(Sender As ucAsyncDLStripe, ByVal TmpFileName As String)
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Nightwalker83
Hi,
I receive
Procedure declaration does not match description of event or procedure having same name
on this line
vb Code:
Private Sub ucAsyncDLHost_DownloadComplete(Sender As ucAsyncDLStripe, ByVal TmpFileName As String)
Just noticed, that in ucAsyncDLHost I still had a Copy&Paste-bug in the Property-Get-Methods:
DownloadStripeByURL
and
DownloadStripeByLocalFileName
But I think that this is not related to the error you reported above - still I'd like when you could download
again from the now updated Zip-Content behind the Download-Link in the Opener-Post - and try the
original project without any changes...
Did you already ripped the two ucAsync___.ctls out of the original project - or was the error encountered
running the original project (as contained in the *.zip)?
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Schmidt
Did you already ripped the two ucAsync___.ctls out of the original project - or was the error encountered
running the original project (as contained in the *.zip)?
I run the project as it was in the zip file to try and understand how things work first.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Nightwalker83
I run the project as it was in the zip file to try and understand how things work first.
Then I'd like you to make a second try with my now definitely updated Zip (which I had to give a different
FileName, AsyncDownloadDemo2.zip, since my WebServer was not releasing the old one properly).
Aside from that problem - even with the older version I could not reproduce your above mentioned Error
("Procedure declaration does not match description of event or procedure having same name")
here on my machine.
Do you run VB6 - or is this by any chance a VB5 you're using?
In case it's VB6, what VB-Servicepack do you have installed (and what Windows-Version are you using)?
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Schmidt
In case it's VB6, what VB-Servicepack do you have installed (and what Windows-Version are you using)?
VB6.0 with SP6.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Nightwalker83
VB6.0 with SP6.
That's good to know - and as said, it would be nice when you could make a second attempt
(maybe in a new unzip-folder, to be entirely sure) - with the updated Zip-File from the Opener-Post-Link ... here the Link again: http://vbrichclient.com/Downloads/As...nloadDemo2.zip
I've just tested Downloading per Browser on two different machines (one running XP, the other Win7, both with VB6/SP6)
and I can't reproduce your error ...
Could you give a bit more information about your attempts - if the error happens again on your machine -
and under what concrete circumstances (IDE, compiled Executable, already whilst starting the project the first time -
or somewhere in-between - or at Form-Unload-Time)?
Re: VB6 Simple Async-Download-Ctl for multiple Files
Where does it put the files I download with your project? I have tried to download by running the project as is and both progress bars are working at the same time but no files appear after the downloads finish.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Nightwalker83
Where does it put the files I download with your project? I have tried to download by running the project as is and both progress bars are working at the same time but no files appear after the downloads finish.
Here is, what I've commented in the DownloadComplete Event-Handler:
Code:
Private Sub ucAsyncDLHost_DownloadComplete(Sender As ucAsyncDLStripe, ByVal TmpFileName As String)
Debug.Print "DownloadComplete for URL: "; Sender.URL
'the complete-event delivers a temporary filename - it is up to the user
'of the Control, to decide what to do with this TmpFile... the usual reaction will be
'a simple File-Renaming (ensuring an implicit Move-Operation on the FileSystem then)
'the Sender is the Control-Stripe of our DownloadListHost-Control - and in the Add-methods
'in the Form-Load-Event above, we have defined a "target-LocalFilename" already, which is
'associated with the matching URL (which was the Source of this completed Download here)
'This target-filename is (so far) only stored as String within the Stripe (Sender.LocalFileName)
'So, yeah - just ensure a proper Move/Rename of the delivered TmpFileName
' Name TmpFileName As Sender.LocalFileName
End Sub
The last line I've left commented out - it was only a (simplified) suggestion, since I do not know,
what the developer decides or prefers to do finally with the delivered TmpFilename.
If you want "to see something in the App.Path", then you will just have to comment the last line in (the one with VBs Name-statement).
Or instead of the simplified single-line Name statement, use an Error-buffered variant, which asks, when the Destination-FIle already exists:
Code:
On Error Resume Next
Name TmpFileName As Sender.LocalFileName
If Err Then
If MsgBox(Err.Description & vbCrLf & "Force a replace with the new File?", vbYesNo) = vbYes Then
Kill Sender.LocalFileName
Name TmpFileName As Sender.LocalFileName
Else
Kill TmpFileName
End If
Err.Clear
End If
Or alternatively (in case you prefer a "Side-by-Side-Auto-Numbering" of new downloaded Files, when similar Names
already exist in the Destination-Folder, you can use the Shell32-Object (or the SHFileOp-API) with the FOF_RenameOnCollision-Flag.
Just adapt the example to your needs - these "final decisions" are deliberately not made within the Downloader-Controls -
instead they are left to the User, over appropriately thrown events like the one above.
Re: VB6 Simple Async-Download-Ctl for multiple Files
This demo uses the AsyncRead method of UserControl, which is "right there" in VB6, but not available in other places, i.e. VBA ...
I use WinHttpRequest a lot, and it supports asynchronous requests. Is it possible to use WinHttpRequest for asynchronous file downloads. Just curious. Haven't tried it yet.
Last edited by bPrice; Mar 29th, 2016 at 10:18 AM.
Re: VB6 Simple Async-Download-Ctl for multiple Files
The cDownloads/cDownload in RC5 is synchrounous as it turned out...
Code:
Private WithEvents d As cDownloads
Sub Test()
Set d = New_c.Downloads
d.Download "http://www.vbforums.com/attachment.php?attachmentid=104369&stc=1&d=1378585318"
End Sub
Private Sub d_DownloadComplete(DownloadObj As vbRichClient5.cDownload, ByVal ErrNum As Long, ErrString As String)
Debug.Print "complete: " & DownloadObj.URL, ErrNum, ErrString
End Sub
Private Sub d_DownloadProgress(DownloadObj As vbRichClient5.cDownload, ByVal Percent As Single, ByVal StatusCode As Long, StatusDescription As String, StatusValue As String)
Debug.Print "progress: " & DownloadObj.URL, Percent, StatusCode, StatusDescription, StatusValue
End Sub
Private Sub d_DownloadStart(DownloadObj As vbRichClient5.cDownload)
Debug.Print "start: " & DownloadObj.URL
End Sub
May I ask how cDownload is implemented? What API/Components it is making use of? Perhaps, the URLDownloadToFile in urlmon.dll?
Last edited by bPrice; Mar 29th, 2016 at 10:27 AM.
Re: VB6 Simple Async-Download-Ctl for multiple Files
What happens if the URL do Not exist ?
Is it better to check somehow existence before AddDownloadJob ? [ if yes , how? is there a fast way? ]
PS
I ask this because I have to do this thing:
download a file of which I only partially know the address.
I know the name of the file and all the url except a number, which for example can be between 1 and 10.
The possible urls can be:
https://site.com/1/Picture.jpg
https://site.com/2/Picture.jpg
https://site.com/3/Picture.jpg
...
I don't know wich one is correct, so I have to try them all.
Last edited by reexre; Jan 16th, 2019 at 07:39 PM.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by reexre
What happens if the URL do Not exist ?
You'll have to try the download of course (in either case)...
If the resource which is described by the URL (the Uniform Resource Locator) does not exist at the serverside,
you will get an appropriate (http-protocol) status-message from the WebServer (in VBs UserControl transported in the AsyncEvents-Status-Params).
Such failing http-requests should "return fast" -
and it's up to you to ensure, that you remove such "Jobs" from the JobList as soon as possible.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Thanks!
So I added blue line to remove Control
Code:
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
On Error Resume Next
If AsyncProp.StatusCode <> vbAsyncStatusCodeEndDownloadData Or AsyncProp.BytesRead = 0 Then
Parent.RaiseDownloadError Me, AsyncProp.StatusCode, AsyncProp.Status
Parent.RemoveByURL Me.URL
CancelDownload
Else
Parent.RaiseDownloadComplete Me, AsyncProp.Value
Parent.RemoveByLocalFileName mLocalFileName 'let's remove ourselves from the List in the Parent-Control
End If
End Sub
Code:
Public Sub RemoveByURL(ByVal URL As String)
Dim CtlKey As String
CtlKey = GetCtlKeyForURL(URL)
If Len(CtlKey) = 0 Then Exit Sub
Controls.Remove CtlKey
VScroll_Change
End Sub
Re: VB6 Simple Async-Download-Ctl for multiple Files
It seems to me that closing the Form containing the ucAsyncDLHost control with active downloads causes an app crash.
Maybe I'm wrong. I'm not sure, but if so, what is the correct way to remove all downloads before closing? (assuming I had not kept track of them)
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by reexre
It seems to me that closing the Form containing the ucAsyncDLHost control with active downloads causes an app crash.
Maybe I'm wrong. I'm not sure, but if so, what is the correct way to remove all downloads before closing? (assuming I had not kept track of them)
There is a Method: Public Sub CancelDownload()
in each "Download-Stripe-Control", which would have to be called, to make sure that "pending async Jobs" are cleared.
Ideally that Cancel-Method should be called, before the ucAsyncDLHost-Method: RemoveByLocalFileName
will remove and destroy the appropriate ucAsyncDLStripe-Control.
Only after all Stripes were cancelled (AsyncJob-wise) and then Removed from the Host-Control,
should the Host-Control itself be unloaded (together with its hosting Form).
Another variant would be, to "Cancel unloading the Form", as long as there are still
"async-stripe-jobs" running (when the Host-Control has a JobCount>0).
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by reexre
BTW: seems that "only controls that are created via Load can be deleted at runtime."
That was probably true for VB5 (where Controls.Add and Controls.Remove didn't exist).
With VB6 one can use both (the old Control-Array-based Load/Unload-mechanism, as well as the new introduced Controls.Add/Remove).
As said - the Controls.Remove-call is currently included in the little wrapper method: RemoveByLocalFileName
For your case (a "well-ordered retreat" in the "Form-TearDown-phase"), the cancelling of all still running async-download-jobs is probably enough
(no need to remove the "async-job-hosting" Stripe-Controls from their Host-Controls-Collection, since this is done anyways under the covers, when the Form finally closes).
Re: VB6 Simple Async-Download-Ctl for multiple Files
The test was completed normally, but did not see the downloaded file: there is no ZIP file in the current directory, and the file after re-specifying the file does not find the downloaded file.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by ChenLin
The test was completed normally, but did not see the downloaded file: there is no ZIP file in the current directory, and the file after re-specifying the file does not find the downloaded file.
Please read the comment, as it sits in the Test-Forms DownloadComplete-EventHandler:
Code:
Private Sub ucAsyncDLHost_DownloadComplete(Sender As ucAsyncDLStripe, ByVal TmpFileName As String)
Debug.Print "DownloadComplete for URL: "; Sender.URL
'the complete-event delivers a temporary filename - it is up to the user
'of the Control, to decide what to do with this TmpFile... the usual reaction will be
'a simple File-Renaming (ensuring an implicit Move-Operation on the FileSystem then)
'the Sender is the Control-Stripe of our DownloadListHost-Control - and in the Add-methods
'in the Form-Load-Event above, we have defined a "target-LocalFilename" already, which is
'associated with the matching URL (which was the Source of this completed Download here)
'This target-filename is (so far) only stored as String within the Stripe (Sender.LocalFileName)
'So, yeah - just ensure a proper Move/Rename of the delivered TmpFileName
' Name TmpFileName As Sender.LocalFileName
End Sub
Re: VB6 Simple Async-Download-Ctl for multiple Files
problem solved:
Code:
Private Sub ucAsyncDLHost_DownloadComplete(Sender As ucAsyncDLStripe, ByVal TmpFileName As String)
Debug.Print "DownloadComplete for URL: "; Sender.URL
Dim aTmp As Variant
aTmp = Split(Sender.URL, "/")
FileCopy TmpFileName, App.Path & "\" & aTmp(UBound(aTmp))
Kill TmpFileName
'the complete-event delivers a temporary filename - it is up to the user
'of the Control, to decide what to do with this TmpFile... the usual reaction will be
'a simple File-Renaming (ensuring an implicit Move-Operation on the FileSystem then)
'the Sender is the Control-Stripe of our DownloadListHost-Control - and in the Add-methods
'in the Form-Load-Event above, we have defined a "target-LocalFilename" already, which is
'associated with the matching URL (which was the Source of this completed Download here)
'This target-filename is (so far) only stored as String within the Stripe (Sender.LocalFileName)
'So, yeah - just ensure a proper Move/Rename of the delivered TmpFileName
' Name TmpFileName As Sender.LocalFileName
End Sub
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by yinxiaodan
How to support a password FTP file download, thank you!
The VB-Usercontrol-Async-support does not offer this via Parameters,
so you'll have to try passing the credentials in the old-fashioned way, by directly including them in the (ftp-)URL:
Code:
ftp://username:password@domain.com/somepath/...
HTH
Olaf
Last edited by Schmidt; Mar 28th, 2019 at 12:50 PM.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by reexre
[https-based secure transfers sometimes work - sometimes not (on older systems)]
UserControl_AsyncReadComplete if fired with SratusCode = 0 just when trying to Connect.
It's basically the same problem we've already discussed some time ago - in a different thread
(and which is still brought up by others - any 2 months or so)...
The SSL/TLS stack of those older systems is sometimes enough (when the sites SSL-certificate is satisfied with "old enough" security-methods/algos) -
but for newer SSL-certs (which specify and require more modern crypto-algos in usually higher bit-length) the https requests might fail on such older systems.
There is not much one can do, other than suggesting to install the newest SSL-Upgrades (along with the newest available IE-install for that system).
An alternative to all the "builtin-MS-crypto- and MS-http-libs" would be libCurl.dll (which comes with its own, usually OpenSSL-based crypto-implementations).
This would then support proper https-requests "down to Win98" - but libCurl (in its Win-Version) is quite large binary-wise - and it comes with a few additional Dll-dependencies -
and has a completely different API.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Schmidt
An alternative to all the "builtin-MS-crypto- and MS-http-libs" would be libCurl.dll (which comes with its own, usually OpenSSL-based crypto-implementations).
Hello; and what about using WinHTTP, would it fail too?
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by Eduardo-
Hello; and what about using WinHTTP, would it fail too?
Probably (many MS-http-wrappers will use the same flat-api-stack in the end - especially when it finally comes to the crypto-stuff).
So you'll have to test (on older systems, which don't have the latest crypto-libs).
Many older sites still allow access via unencrypted, plain http-channels - so that could be (or seems like) a fallback-option which would always work...
Though on most modern sites, https is enforced via a clientside redirect - as e.g. the URL reexre has posted: https://miorsoft.github.io/Site/Proj...bs/1/00002.jpg
even when you try to navigate to it via "plain http://..." - you will end up with an enforced https-request in the end.
ssllab's ssltest reports that IE11 uses TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 on Win7 and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 on Win10.
The problem for Schannel on XP is that this particular server advertises support for TLS 1.2 only and no fallback to 1.1 or 1.0 is allowed. Probably allowing TLS 1.2 (and TLS 1.1) in the Schannel's registry settings might help.
Try merging this .reg file (reboot required)
Code:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\WPA\PosReady]
"Installed"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"DisabledByDefault"=dword:00000000
Edit: This will probably need KB4019276 installed on the machine beforehand.
cheers,
</wqw>
Last edited by wqweto; Mar 29th, 2019 at 04:48 AM.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by yinxiaodan
Does RC5 have the function of FTP upload and download with password?
No FTP-Upload-feature is encapsulated in a convenience-class, no...
For the Download-direction though, you could try the cDownloads-Class (just tested this again on Win10 with my own FTP-server successfully):
Code:
Option Explicit
Private WithEvents DLs As cDownloads
Private Sub Form_Load()
Dim Host: Host = "MyHostDomain.de"
Dim Path: Path = "/pdf/SomePdfFile.pdf"
Set DLs = New_c.Downloads
DLs.Download "ftp://" & Host & Path, dl_FTP, , , "MyUsername", "MyPassword"
End Sub
Private Sub DLs_DownloadStart(DownloadObj As cDownload)
Debug.Print "DL-Start with URL: " & DownloadObj.URL
End Sub
Private Sub DLs_DownloadProgress(DownloadObj As cDownload, ByVal Percent As Single, ByVal StatusCode As Long, StatusDescription As String, StatusValue As String)
Debug.Print "DL-Progress with URL: " & DownloadObj.URL, Percent, StatusCode, StatusDescription, StatusValue
End Sub
Private Sub DLs_DownloadComplete(DownloadObj As cDownload, ByVal ErrNum As Long, ErrString As String)
Debug.Print "DL-Complete with URL: " & DownloadObj.URL, ErrNum, ErrString, DownloadObj.GetContentLen
End Sub
Note, that the cDownloads-Class is not a "full FTP-Client" (it's "true to its name" - and does only downloads...
e.g. it does not support Dir-Listings - and so you will have to know the Filename and Path beforehand on your FTP-Server).
FWIW - I've uploaded a fully implemented FTP-Client of mine here: http://www.vbforums.com/showthread.p...n-Winsock-ocx)
This is > 20 years old code, based on the Winsock.ocx - but with full control over the FTP-command-channel -
Maybe that helps already - but it's surely not the only VB6-FTP-client-implementation when you google a bit...
In case you need this for your own WebHosting (to synchronize between local Files and your production-environment)...
the first thing I've done on my own WebHost was, to implement appropriate *.asp-Scripts, which allowed me Dir-Listings and File-Transfers directly and secure via https.
So, personally I try to avoid FTP-stuff as often as I can - it's old-fashioned - and only secure with extensions like FTPS or SFTP -
and firewall-wise always a nightmare to "configure and make work" at some customer.sites (especially when some customers have thrown Proxies into the mix in addition).
Re: VB6 Simple Async-Download-Ctl for multiple Files
I admire your selfless efforts. RC5 has made my programming much easier and helped me tremendously. Do you have a follow-up upgrade plan? It is suggested that donation portals can be set up on your website if possible, so that RC5 can develop better. Thank you again, Olaf.
Re: VB6 Simple Async-Download-Ctl for multiple Files
Originally Posted by yinxiaodan
RC5 has made my programming much easier and helped me tremendously.
Do you have a follow-up upgrade plan?
There is not much missing in the RC5 currently (aside from perhaps a few classes, which wrap libCURL -
or some other platform-independent "web-protocol-access-lib" - with the goal to get independent from the MS-inet-stack)
Originally Posted by yinxiaodan
In addition, VB6 to control file upload and download, what is a good way to achieve fast and asynchronous execution?
Upload- and Download to WebServers?
Using what protocol?
If it's "Web-Servers" and http/https...:
- the Download-direction is usually easy (e.g. for static files, no special serverside script is needed)
- whereas for Uploads you will need appropriate serverside scripts, which handle the incoming "raw-file-data" (which can be send in several different formats).