Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.6k views
in .NET FTP by (1.5k points)
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

3 Answers

0 votes
by (1.8k points)
If I got your post correct I think what you are looking for is the c.Downloaded event.

This is a delegate with the following fingerprint:
FtpFileTransferEventHandler(void(object, FtpFileTransferEventArgs)target)

So what you could do is
c.Downloaded += new FTPFileTransferEventHandler(OnFtpTransfered);

private void OnFtpTransfered(object sender, FtpFileTransferEventArgs e){
Console.WriteLine(String.Format("File {0} just finished transfering", e.RemoteFile);
}


I wrote the code on freehand, so there might be some mistakes in it, but I think you get the ghist right..
Also, I didn't write it in VB because I don't know the syntax of that language very well.

Hope that helped
Boris
0 votes
by (1.5k points)
Thanks Boris
That gives me something to think about.
If I get it working I'll post the results here.

cheers
Malcom
0 votes
by (1.8k points)
No problem.
With my current project I have been in about the same situation, and have been cursing on this whole FTP thing myself.
I hope my experiences can help you and maybe I can profit from your experiences in the synchronising thing in the future ..

I must add that the EDT support has been most helpfull throughout the whole time...
The library was not very cheap (took some effort convincing my boss), but it has been worth it already.

Categories

...