|
|
Comments and Discussions
|
|
 |

|
how can download a file from password protected host in this method ?
when i try to download a file from username and password protected host my app say download complated
sry for my bad eng
|
|
|
|

|
Sometimes the variable CurrentFilePercentage reports Infinity. Can this be fixed? It seems to happen randomly on different downloads.
|
|
|
|

|
It seems like there is only certain code I can put in the ProgressChanged event. If I update a progressbar, that works, but if I try to update a string in a listview it causes a target of invocation exception. Is this a thread safety problem? What can I do? I need to be able to update status inside a listview control.
|
|
|
|

|
Found the problem was in my code. Sorry.
|
|
|
|

|
what i have noticed in the downloadFile Sub in FileDownloader.vb that in
this line :
currentPackageSize = webResp.GetResponseStream().Read(readBytes, 0, Me.PackageSize)
it calls GetResponseStream every time on the while loop for example :
in 646 kb file it calls it about 1292 times, so i figured a way to call this only 1 time!
which makes the downloading process faster about 66% percent more than the original code, here it is :
Dim ResStream As IO.Stream = webResp.GetResponseStream()
Dim readBytes(2047) As Byte
Do
currentPackageSize = ResStream.Read(readBytes, 0, 2048)
If currentPackageSize = 0 Then Exit Do
writeStream.Write(readBytes, 0, bytesread)
Loop
try it out guys and tell me what you think.
|
|
|
|

|
Could you elaborate a little more, for people like me that are not really experts on the matter, how would the code look like after your change?
Because I tried to comment that line, and play around with yours and I wasn't succesful with it.
Thanks very much
|
|
|
|

|
Do the following and it should work fine:
1- go to FileDownloader.vb
2- go to downloadFile sub
3- and then just copy and paste this:
Private Sub downloadFile(ByVal fileNr As Int32)
m_currentFileSize = 0
fireEventFromBgw([Event].FileDownloadAttempting)
Dim file As FileInfo = Me.Files(fileNr)
Dim size As Int64 = 0
Me.PackageSize = 2048
Dim readBytes(Me.PackageSize - 1) As Byte
Dim currentPackageSize As Int32
Dim writer As New FileStream(Me.LocalDirectory & "\" & file.Name, IO.FileMode.Create)
Dim speedTimer As New Stopwatch
Dim readings As Int32 = 0
Dim exc As Exception
Dim webReq As HttpWebRequest
Dim webResp As HttpWebResponse
Try
webReq = CType(Net.WebRequest.Create(Me.Files(fileNr).Path), HttpWebRequest)
webResp = CType(webReq.GetResponse, HttpWebResponse)
size = webResp.ContentLength
Catch ex As Exception
exc = ex
End Try
m_currentFileSize = size
fireEventFromBgw([Event].FileDownloadStarted)
If exc IsNot Nothing Then
bgwDownloader.ReportProgress(InvokeType.FileDownloadFailedRaiser, exc)
Else
m_currentFileProgress = 0
Dim ResStream As IO.Stream = webResp.GetResponseStream()
While m_currentFileProgress < size
If bgwDownloader.CancellationPending Then
speedTimer.Stop()
writer.Close()
webResp.Close()
Exit Sub
End If
trigger.WaitOne()
speedTimer.Start()
currentPackageSize = ResStream.Read(readBytes, 0, Me.PackageSize)
m_currentFileProgress += currentPackageSize
m_totalProgress += currentPackageSize
fireEventFromBgw([Event].ProgressChanged)
writer.Write(readBytes, 0, currentPackageSize)
readings += 1
If readings >= Me.StopWatchCyclesAmount Then
m_currentSpeed = CInt(Me.PackageSize * StopWatchCyclesAmount * 1000 / (speedTimer.ElapsedMilliseconds + 1))
speedTimer.Reset()
readings = 0
End If
End While
speedTimer.Stop()
writer.Close()
webResp.Close()
fireEventFromBgw([Event].FileDownloadSucceeded)
End If
fireEventFromBgw([Event].FileDownloadStopped)
End Sub
4- Compile and run!
tell me the results
modified 18 Oct '12 - 17:26.
|
|
|
|

|
Yes it works good! Thanks!
|
|
|
|

|
SimpleDownloadFile.suo will not convert?
|
|
|
|

|
it only creates the files but its not downloading am i doing something wrong
i now know the problem its not downloading .txt files wy?
|
|
|
|

|
I had the same problem. How i fixed it was to use the following code in my Form_Load event
Private Sub Setup_Form_Two_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_Downloader.SupportsProgress = True
End Sub
Hope that helps
|
|
|
|

|
this is good articel what i found....
but how i can add information with file size in listbox, not just filename...
sorry, my english not well..
|
|
|
|

|
how can i download each file if all the link stored in datagridview?
|
|
|
|
|

|
I know I'm going to look incredibly thick here, but oh well:
How do you add a class to a project?
I've tried adding a reference, but none of the files in the Bn folder will work. I've tried adding the three files in the Bn folders to my project, no luck. I've done something like this before, and I thought you just added a reference...
I'm using VB Express 2010, which is where I'm thinking some of the errors are coming in.
Many thanks! I actually started using your other downloader, but it stops at 20MB, the file I'm trying to get it to download is 480MB
James
|
|
|
|

|
Actually I think I might have done it (doh).
I've copied the code from the FileDownloader.vb file in Bn/Classes to a new, empty class file in my project. Seems to have worked, no errors, just some warnings etc.
If I need to something else let me know!
James
|
|
|
|

|
All you need to do is the following
in Solution Explorer right click the project name, then scroll down and highlight 'Add', this will open a new menu where you need to select 'Existing Item'.
This will allow you to select the Class you have downloaded making it available in your project
|
|
|
|

|
5
|
|
|
|

|
I love this as I'm trying to make an update module for my application, but it's really slowing down my computer. It might be that my CPU is just slow, but what about this at your own computer?
Thanks.
|
|
|
|

|
Hey,
I'm not noticing any strain on my system while downloading. Do you notice similar effects when downloading at the same speed to the same location via another application? Also, can you check if you have problems when you use the demo application? (That will rule out wrong implementation as a cause.)
Although I haven't had any problems, that doesn't say much. I had a 6GiB memory leak a few months ago without noticing for over an hour (the disadvantage of having a good machine I suppose).
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
heyy
great workk , what if i want to download from mediafire and add a password
thx in advance
|
|
|
|

|
Hey,
I'm not familiar with mediafire, but you can't download any password protected files with this class, unless you first gain access in some way. This class does not support the later part (and ATM I don't see how it could, and what would be the use anyway).
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
I've posted code about credential, and I have a few question to you.
I want to use your class in my application and i need to do some operation with downloaded files.
I must process files one after another.
1/ Is it a good idea to use downloader.Pause for process file in downloader_FileDownloadSucceeded procedure? Is it prevent to download the next one?
sub downloader_FileDownloadSucceeded (....)
downloader.Pause
.. do something
downloader.Resume or downloader.Stop
end sub
2/ How to catch error 404 if no file found on server? other errors...
I have file with length= 0 after error
3/ How to download file to Stream instead of file
4/ how to get file type from CurrentFile object (is it text/html or jpg or png)
|
|
|
|

|
Hey,
1. If you use the Pause method, the current download will be put on hold, and nice this version does not feature the ability to download multiple files at once, this will also prevent the next download from being executed. Multiple simultaneousness downloads and the ability to cancel and resume individual downloads are planned features. I won't have time to work on it in the next few months though, so I encourage you to try write them yourself and publish the code
2, 3, 4. The FileDownloader class does simply not support these features, but it are good suggestions for what can be added. Like I mentioned before, feel free to contribute
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
a few additions
Private m_currentContentType As String
'*************
' Sub downloadFile
m_currentContentType = ""
Dim type As String = ""
type = webResp.ContentType
' if error delete file with length=0
if
If exc IsNot Nothing Then
'added
speedTimer.Stop()
writer.Close()
If webResp IsNot Nothing Then webResp.Close()
cleanUpFiles(m_fileNr, 1)
bgwDownloader.ReportProgress(InvokeType.FileDownloadFailedRaiser, exc)
else
endif
'*****************
''' <summary>Gets the ContentType of the current file</summary>
Public ReadOnly Property CurrentContentType() As String
Get
Return m_currentContentType
End Get
End Property
'***********************
'FileInfo structure new NEW()
'so we can change name of downloaded file, and more - it directory
' for example Path = "C:\temp" like BasePath or ""
'sName = "0\11\333\myfile.txt"
Public Sub New(ByVal path As String, ByVal sName As String)
Me.Path = path
Me.Name = sName
End Sub
'after that everywhere i use IO.Path.Combine
Dim fullPath As String = IO.Path.Combine(Me.LocalDirectory, Me.Files(fileNr).Name)
' in filedownload sub
'added
If Not Directory.Exists(IO.Path.GetDirectoryName(IO.Path.Combine(Me.LocalDirectory, file.Name))) _
Then Directory.CreateDirectory(IO.Path.GetDirectoryName(IO.Path.Combine(Me.LocalDirectory, file.Name)))
'your code
Dim writer As New FileStream(IO.Path.Combine(Me.LocalDirectory, file.Name), IO.FileMode.Create)
|
|
|
|

|
what were your wrong assumption you had about multithreading. is there something that others can learn from what you found?
cheers,
Donsw
My Recent Article : Backup of Data files - Full and Incremental
|
|
|
|

|
Hey,
Before I created this class I was oblivious to the fact that objects get locked and can't always be set via all threads without the proper extra code. I also never used to ReportProgress event of the BackGroundWorker.
After creating this class I did some more reading on multi threading to get a better grip on it, and I can recommend the following series of articles: Beginners Guide To Threading In .NET Part 1 of n[^]
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
this is good information for everyone, you shoudl have added that to the points of interest section. good points and good article
cheers,
Donsw
My Recent Article : Backup of Data files - Full and Incremental
|
|
|
|

|
I've just submit a new version of this article with the explanation of my previous post under points of interest, and the slightly updated version of my class
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
much better good work
cheers,
Donsw
My Recent Article : Backup of Data files - Full and Incremental
|
|
|
|

|
Hi - found this really good nad hoping to utilise the class in my programs.
Just one question, how do you set credentials when using the class?
|
|
|
|

|
Hey,
I don't know actually. If you could provide me with an exmaple of how to do this in VB.Net or C#.Net I'll have a look at it and maybe implement it into this class.
Also note that I have slightly updated code here: http://code.bn2vs.com/viewtopic.php?t=150[^] (I will update this article soon)
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
Thank you for nice tool! I've added credential in your class
'*****************
'Proxy
Private m_IsUseProxy As Boolean
Private m_Proxy As New WebProxy()
'**********************
Public Property IsUseProxy() As Boolean
Get
Return m_IsUseProxy
End Get
Set(ByVal value As Boolean)
m_IsUseProxy = value
End Set
End Property
'****************
Public Sub SetProxy(ByVal Host As String, ByVal Port As Integer, _
ByVal UserName As String, ByVal Pwd As String, ByVal Domain As String)
m_Proxy = New WebProxy(Host, Port)
Dim Credential As New NetworkCredential(UserName, Pwd, Domain)
m_Proxy.Credentials = Credential
End Sub
'*****************
Dim webReq As HttpWebRequest = CType(Net.WebRequest.Create(Me.Files(fileNr).Path), HttpWebRequest)
'Was Added
If m_IsUseProxy Then
webReq.Proxy = m_Proxy
End If
'End added
Dim webResp As HttpWebResponse = CType(webReq.GetResponse, HttpWebResponse)
But i did not add ErrorHandling.
I can't found how to GetDefaultProxy in .NET 3.5
And I have one question, i'll post it in new tread
|
|
|
|

|
Hey,
Thnx a lot for the contribution!
I'll add your code to the class and put you in the credits
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
You should also consider using BITS (Background Intelligent Transfer Service)[^] which is a Windows Service available since Windows 2000 and used by Windows Update service.
It has many cool features: it's a service (always on), uses HTTP, can be paused, manages errors, etc. Latest versions also support upload to an IIS web server.
You can find more details (and a .NET wrapper) in this CodeProject article: SharpBITS.NET - wrapper for BITS API[^]
|
|
|
|

|
Hey,
Yesterday someone also suggested that on the C# article. See the url underneath for my reply
C# .NET Background File Downloader[^]
Thnx for the suggestion though
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|

|
Hey guys,
I've created a slightly updated version with some extra functionality, and I'm working on a C#.Net implementation (with WPF demo). I'll release both within a week
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
Hey, thanks for the great program, article, and code!
I was testing out your sample program (with the default three files in the textbox), and it was going fine, but immediately after it finished downloading the first file, an error box comes up, reporting that an "Overflow error has occurred as a result of an arithmetic operation".
However, the program did keep downloading the files, and it didn't seem to affect anything (the program didn't stop downloading, although the error box was still displayed).
I would be grateful if you could look into this issue, as I would like to be 100% sure that the same behaviour would not be displayed to the users of my product.
Thanks in advance,
Anthony.
|
|
|
|

|
Hey,
I am not getting this error (just tested again).
Could you be more precise about the error details you get? Also, which version of VS are you using? I'm using 2008, and wrote a few things that might cause warnings/errors depending on your configuration. If this is the case, it'll be easy to fix.
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
Hey,
I have just tested the program multiple times again. I experienced the same behaviour each time, and have posted the contents of the error message below:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.OverflowException: Arithmetic operation resulted in an overflow.
at Downloader.downloader_ProgressChanged()
at Downloader._Lambda$__9(Object a0, EventArgs a1)
at Bn.Classes.FileDownloader.bwgDownloader_ProgressChanged(Object sender, ProgressChangedEventArgs e)
at System.ComponentModel.BackgroundWorker.OnProgressChanged(ProgressChangedEventArgs e)
at System.ComponentModel.BackgroundWorker.ProgressReporter(Object arg)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
SimpleDownloadFile
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Ant/Local%20Settings/Temporary%20Internet%20Files/Content.IE5/PEDCXAS4/FileDownloaderDemo%5B1%5D/FileDownloaderDemo.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
----------------------------------------
This message came up just after the progress bar for the second file completed. The error alternates between all three files (sometimes after the first has downloaded, sometimes after the second, and sometimes after the third). I am using VS 2008 Standard Edition.
Thanks,
Anthony.
|
|
|
|

|
Hey,
I'm also getting it, and am now trying to locate it. I only get it at roughly ~10% of the times is download those 3 files with it though.
Cheers
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|

|
The error occurs in Private Sub downloader_ProgressChanged, in the demo component.
downloader.CurrentFileSize sometimes has the value 0, causing an overflow when the CurrentFilePercentage property is calculated (division by zero). I can not explain this though, since the CurrentFileSize never returns 0 (I check this inside the property itself with an if else structure), so have no idea how to solve this.
A way of ignoring it is putting 'On Error Resume Next' on the first line in the downloader_ProgressChanged sub.
If anyone finds the reason for this bizarre behaviour, please let me know
Cheers
BN
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
Hey,
Thanks for checking this one out and finding a work-around.
Anthony.
|
|
|
|
|

|
Cheers
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|

|
Incorrect category, not C or C . .
|
|
|
|

|
I thought these categories where referring to the .Net languages. And although this is written in VB.Net, it can easily be compiled to something usable in any other .Net application.
I find it sad you go just vote 1 only for this.
|
|
|
|

|
dont worry bn2vs im a Article poster my self I just take a look at this guy's profile and figure that he has a lot of message post with same "Incorrect Category" but with no Article submitted by this guy i give 5 to your Article and if you like see RPN Compiler for PIC Microcontroller Evaluation Engine 1.4[^]
qwertyuiop
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A multithreaded file downloader with progress details, speed info and more
| Type | Article |
| Licence | GPL3 |
| First Posted | 22 Apr 2009 |
| Views | 75,666 |
| Downloads | 7,517 |
| Bookmarked | 95 times |
|
|