Hi
I have some code that queues a bunch of files for download and then continues with the main app's processes.
Upon successful download the files are deleted from the server.
My question is how to retrieve the filename of the file currently downloading?
I call the delete method from the 'onDownload' event but can't see a way to give it the current filename.
I could queue the deletions as well from the 'onConnect' event but would like to kill them as downloaded.
here's the guts of my code:
Private Sub OnConnect(ByVal ar As IAsyncResult)
Dim c As SecureFTPConnection = CType(ar.AsyncState, SecureFTPConnection)
c.EndConnect(ar)
Try
AddToList("Connecting to server " & ftp_IP)
' get the current working directory and files
tryAgain:
Dim files As String() = ftpConnection.GetFiles()
Dim iFiles As Integer = UBound(files) + 1 ' zero based
AddToList("Total available files = " & iFiles)
If iFiles > 0 Then
' add names to display
Dim filename As String
For Each filename In files
doFileList(filename)
Next
Dim newFile As String
For Each filename In files
' download it with a new name
newFile = exportFolder & filename ' mapped drive to leitch folder
ftpConnection.BeginDownloadFile(newFile, filename, New AsyncCallback(AddressOf OnDownload), ftpConnection)
AddToList("Queued file " & filename & " for download.")
Application.DoEvents()
Next filename
bDownloaded = True
Else
setWarningLblGreen()
AddToList("Sleeping....")
Sleep(60000) ' 1 minute
GoTo tryagain
End If
Catch e As Exception
AddToList(e.Message)
MessageBox.Show(e.Message, "Connect err")
End Try
End Sub 'OnConnect
Private Sub OnDownload(ByVal ar As IAsyncResult)
Dim c As SecureFTPConnection = CType(ar.AsyncState, SecureFTPConnection)
c.EndDownloadFile(ar)
' delete the file from the server?
AddToList("Downloaded file")
If bDelete Then
ftpConnection.BeginDeleteFile(filename, New AsyncCallback(AddressOf OnDelete), ftpConnection)
AddToList("Deleted file from server '" & filename & "'")
End If
End Sub 'OnDownload
any thoughts anyone?
cheers
Malcom