Example for using Callback to update progress bar during .PutFile

Mar 26, 2010 at 4:38 PM

Hi Alex,

First off, bravo on the component... it has been a joy to learn and use.

I was wondering if you have an example of how to use the TransferCallback Param that is available in the PutFile function.  I haven't used callbacks before, so its all new.

Many thanks, and I look forward to your documentation!

Coordinator
Mar 26, 2010 at 10:13 PM

Hi M1sandman,

 

thanks for appreciating this project :-)

about the callback, here's a simple example straight from the command line client sources (available in Source Code area as well).

 

Cheers,

Alessandro Pilotti [MVP / IIS]

 

 

            client.PutFiles(localDirName, remoteDirName, localFilePattern, EPatternStyle.Wildcard, options.recursive, new FileTransferCallback(TransferCallback));

 

        client.PutFiles(localDirName, remoteDirName, localFilePattern, EPatternStyle.Wildcard, options.recursive, new FileTransferCallback(TransferCallback));

...

        private static void TransferCallback(FTPSClient sender, ETransferActions action, string localObjectName, string remoteObjectName, ulong fileTransmittedBytes, ulong? fileTransferSize, ref bool cancel)
        {
            switch (action)
            {
                case ETransferActions.FileDownloaded:
                case ETransferActions.FileUploaded:
                    OnFileTransferCompleted(fileTransmittedBytes, fileTransferSize);                    
                    break;
                case ETransferActions.FileDownloadingStatus:
                case ETransferActions.FileUploadingStatus:
                    OnFileTransferStatus(action, localObjectName, remoteObjectName, fileTransmittedBytes, fileTransferSize);
                    break;
                case ETransferActions.RemoteDirectoryCreated:
                    if (options.verbose)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Remote directory created: " + remoteObjectName);                        
                    }
                    break;
                case ETransferActions.LocalDirectoryCreated:
                    if (options.verbose)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Local directory created: " + localObjectName);                        
                    }
                    break;
            }
        }


 

 

 

 

Mar 27, 2010 at 12:06 AM

Alex,

Thanks so much for the quick reply, you put me on the right track and its working wonderfully!

Best,

Steve

Tampa, FL

Mar 29, 2010 at 9:09 PM

Hi Alex,

One more question -- I see in one of the overloads for .Connect that you have the ability to set the timeout -- is there any other way to set the timeout than using that overload (since I'm not using all the client certificate, etc?)

Many thanks again!