Xceed .NET Libraries Documentation
FileTransferStatus Event
Example 


Xceed.Ftp Assembly > Xceed.Ftp Namespace > FtpClient Class : FileTransferStatus Event
Raised for every 4Kb sent or received during a file transfer.
Syntax
'Declaration
 
Public Event FileTransferStatus As FileTransferStatusEventHandler
'Usage
 
Dim instance As FtpClient
Dim handler As FileTransferStatusEventHandler
 
AddHandler instance.FileTransferStatus, handler
public event FileTransferStatusEventHandler FileTransferStatus
Event Data

The event handler receives an argument of type FileTransferStatusEventArgs containing data related to this event. The following FileTransferStatusEventArgs properties provide information specific to this event.

PropertyDescription
Gets the percentage of the bytes that have been transferred for the entire group of files to transfer.  
Gets the average throughput for the entire group of files being transferred, in bytes per second.  
Gets the total amount of bytes that were skipped so far for the group of files being transferred.  
Gets the total amount of bytes of all files that will be transferred.  
Gets the total amount of bytes transferred so far for the group of files being transferred.  
Gets the percentage of bytes transferred for the current file.  
Gets the current file's average throughput in bytes per second.  
Gets the amount of bytes that were skipped for the current file.  
Gets the total amount of bytes for the current file.  
Gets the amount of bytes transferred for the current file.  
Gets the percentage of files that have been transferred so far.  
Gets the total number of files skipped so far.  
Gets the total number of files to transfer.  
Gets the total number of files transferred so far.  
Gets the path and filename of the local file.  
Gets the filename of the remote file.  
Remarks

When receiving files with the ReceiveFile method, some FTP servers will not provide the size of the file currently being received and therefore, some values of the FileTransferStatusEventArgs will be 0. If you require these particular statistics, you can use the ReceiveMultipleFiles method instead of the ReceiveFile method. The ReceiveMultipleFiles method requests a complete listing from the FTP server before receiving any files. The FTP client therefore obtains the file sizes of each file being received and can then provide these statistics during the FileTransferStatus event. If you use this technique, keep in mind that the receive operation will be slightly slower (due to the extra listing operation) and that it will not be possible to change the local filename of the file.

Example
The following example demonstrates how to use the FileTransferStatus event to display progress information during a multiple-file transfer. This example assumes that you are in a Windows application and that the form contains 2 labels and 2 progress bars.
Xceed.Ftp.Licenser.LicenseKey = "FTNXX-XXXXX-XXXXX-XXXX" ' Set license key here to deploy 

Dim ftp As New FtpClient()

' Subscribe to the FileTransferStatus event.
AddHandler ftp.FileTransferStatus, AddressOf Me.file_transfer

ftp.Connect( "localhost" )
ftp.Login()

ftp.ReceiveMultipleFiles( "ClientFiles\*", "d:\", True, True )

ftp.Disconnect()

Private Sub file_transfer( ByVal sender As Object, ByVal e As FileTransferStatusEventArgs )

  If e.BytesTransferred = 0 Then
    label2.Text = "Receiving file " + e.LocalFilename
    label1.Text = "Receiving file #" + e.FilesTransferred.ToString() + " of " + e.FilesTotal.ToString()
  
    label1.Refresh()
    label2.Refresh()
  End If
  
  progressBar2.Value = e.BytesPercent
  progressBar1.Value = e.AllBytesPercent
End Sub
Xceed.Ftp.Licenser.LicenseKey = "FTNXX-XXXXX-XXXXX-XXXX" // Set license key here to deploy 

FtpClient ftp = new FtpClient();

// Subscribe to the FileTransferStatus event.
ftp.FileTransferStatus += new FileTransferStatusEventHandler( this.file_transfer );

ftp.Connect( "localhost" );
ftp.Login();

ftp.ReceiveMultipleFiles( @"ClientFiles\*", @"d:\", true, true );

ftp.Disconnect();

private void file_transfer( object sender, FileTransferStatusEventArgs e )
{
  if( e.BytesTransferred == 0 )
  {
    label2.Text = "Receiving file " + e.LocalFilename;
    label1.Text = "Receiving file #" + e.FilesTransferred.ToString() + " of " + e.FilesTotal.ToString();
  
    label1.Refresh();
    label2.Refresh();
  }
  
  progressBar2.Value = e.BytesPercent;      
  progressBar1.Value = e.AllBytesPercent;      
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also