Transfering a file via FTPS

dstrough

New member
Joined
Aug 21, 2009
Messages
3
Programming Experience
1-3
Hey guys,

First of all, I want to apologize to you up front if I did not post this in the right forum. Second, I'm sorry in advance if I don't understand your response. I have taken 2 semesters of VBasic back in college and have been thrown into learning VB.NET which is quite a different monster, indeed.

Background:
I am using Alex Pilotti's FTPS assembly (Alex FTPS Client - Home) which is a freeware open source solution to my FTPS woes. The source code is available for download on his site. This is an awesome assembly! Thanks Alex!

I have tried emailing him requesting help, but have not received an answer, so I am going to the forums.

There is no MSDN documentation on his assembly (coming soon according to his website), but some of you experienced .NET coders out there should be able to look through the source code of the assembly and see how it might fit together. I will still post the relevant portions of the code here so that you don't have to download it unless you want to.

Here is my issue:

I am trying to get asynchronous callbacks of the current file transfer progress
Here is the line I am calling the method which initiates the transfer:

VB.NET:
Dim ulReturn As ULong
ulReturn = client.PutFile(localPath & filename, remotePath & filename, Nothing)

According to the assembly: The putfile method has several overloads. The one I am concerned with is:

VB.NET:
        /// <summary>
        /// PutFile overload to easily transfer a file from local to remote
        /// </summary>
        /// <param name="localFileName"></param>
        /// <param name="remoteFileName"></param>
        /// <returns>Transferred bytes count.</returns>
        public ulong PutFile(string localFileName, string remoteFileName)
        {
            return PutFile(localFileName, remoteFileName, null);
        }

There is a secondary overload which may be applicable:

VB.NET:
        /// <summary>
        /// PutFile overload to easily transfer a file from local to remote
        /// </summary>
        /// <param name="localFileName"></param>
        /// <param name="remoteFileName"></param>
        /// <param name="transferCallback"></param>
        /// <returns>Transferred bytes count.</returns>
        public ulong PutFile(string localFileName, string remoteFileName, FileTransferCallback transferCallback)
        {
            using (Stream s = PutFile(remoteFileName))
                return SendFile(localFileName, remoteFileName, s, transferCallback);
        }

The putfile method is accessing a delegate. I admit to being stupid when it comes to delegates. I have been trying to understand them all morning by reading various websites and tutorials, but it has confused me even more. Here is the delegate from the assembly

VB.NET:
    /// <summary>
    /// Callback used during file transfers to notify the caller about any command progress. 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="action"></param>
    /// <param name="localObjectName"></param>
    /// <param name="remoteObjectName"></param>
    /// <param name="fileTransmittedBytes"></param>
    /// <param name="fileTransferSize"><c>null</c> if not available (e.g. the server does not support the SIZE command).</param>
    /// <param name="cancel"></param>
    public delegate void FileTransferCallback(FTPSClient sender, ETransferActions action, 
                                              string localObjectName, string remoteObjectName,
                                              ulong fileTransmittedBytes, ulong? fileTransferSize, 
                                              ref bool cancel);

I have been researching asynchronous delegate callbacks, background worker threading (which I currently have implemented but is not working) etc.. I really am at a loss here and am not sure how to proceed in order to get real time updates on how many bytes have been transferred and send that to my progressbar.value within my bgWorkFTP_ProgressChanged method.

Any guidance would be much appreciated!!

Regards,

Doug
 
Back
Top