


Private WithEvents DownloadClient As New () Private WithEvents UploadClient As New () Notice that exist two webclients objects because a single webclient can't upload as async at the same time that it tries to download as asynchronous so it should throw an E/S exception then I use one client for uploads and other for downloads. Then to handle the events (only for async methods ofcourse) I do this: Public Sub DownloadFile(ByRef DownloadClient As WebClient, ''' Indicates the WebClient object to download the file. UploadFile(New Uri(filepath), "STOR", localfilepath) UploadFileAsync(New Uri(filepath), "STOR", localfilepath) Optional ByVal filepath As String = Nothing,įilepath = Me.host & "/" & New IO.FileInfo(localfilepath).Name

Public Sub UploadFile(ByRef UploadClient As WebClient, ''' Indicates whether the download should be an Asynchronous operation, ''' Specifies the local path where to save the downloaded file. ''' Indicates the WebClient object to upload the file. In the ftp class (which is just an helper class of ftpclient library ) I've wrote these methods: ''' Has been declared with the withevents keyword. NOTE: And just to clarify, of course there is no need to addres the handler manually at runtime to any variable that The unique reason why the events aren't raised (as said before by in the comments above) is that only the asynchronous webclient methods raises those events, then the only way to solve it is using the async methods, and really there is no need to raise events with the blocking methods, It just got me a little confused when trying to raise webclient events for first time, I did not thinked about what I was trying to do with the right logic. DownloadFile(New Uri(filepath), localfilepath) DownloadFileAsync(New Uri(filepath), localfilepath) Credentials = New NetworkCredential(Me.user, Me.pass) Optional ByVal Asynchronous As Boolean = False) The ftp object DownloadFile method is this: Public Sub DownloadFile(ByRef DownloadClient As WebClient, Private Sub Client_DownloadCompleted(ByVal sender As WebClient,īyVal e As DownloadDataCompletedEventArgs) _ Private Sub Client_DownloadProgress(ByVal sender As WebClient,īyVal e As DownloadProgressChangedEventArgs) _ Private WithEvents client As New ()įtp.DownloadFile(client, "/inputfile.ext", "c:\targetfile.ext") I've tried the same with the webclient upload EventArgs and them worked, but the Download EventArgs don't.
#Crowfall download client not working code#
I would like to know why this piece of code is not working, it not throws any exception, the file is downloaded, just the events are not.
