Xceed .NET Libraries Documentation
FxpCopy Method


Xceed.Ftp Assembly > Xceed.Ftp Namespace > FtpClient Class : FxpCopy Method
Directs two specified FTP clients to perform a FXP (server to server) file transfer from the specified source FTP server to the specified destination FTP server.
Overload List
OverloadDescription
 
 
 
Exceptions
ExceptionDescription
If a parameter is null.

If an empty string was specified.

If the property values of the source and/or destination FTP client prevent a proper FXP transfer. Refer to the exception message for details.

Remarks

For a FXP transfer to work, one client needs to have its FxpPassiveTransfer property set to true. The other client's value for the property needs to be set to false. Also, both clients must use the same value for the RepresentationType and TransferMode properties.

Example
// Create a FTP client to control our source server
FtpClient sourceClient = new FtpClient();

// Create a FTP client to control our destination server
FtpClient destinationClient = new FtpClient();

try
{
  // Connect to the source server
  sourceClient.Connect( "localhost", 21 );

  /* FXP transfers cannot be performed over encrypted data channels. While it is ok
   to encrypt the control channel, the data channel must remain clear. The DataChannelProtection.Clear
   value ensures that. */
  //sourceClient.Authenticate( AuthenticationMethod.Tls, VerificationFlags.None, null, DataChannelProtection.Clear );
  
  // Login to the source server
  sourceClient.Login( "normal", "normal" );

  // Connect to the destination server
  destinationClient.CertificateReceived += delegate( object sender, CertificateReceivedEventArgs e )
  {
    e.Action = VerificationAction.Accept;
  };

  destinationClient.Connect( "localhost", 10021 );

  /* FXP transfers cannot be performed over encrypted data channels. While it is ok
   to encrypt the control channel, the data channel must remain clear. The DataChannelProtection.Clear
   value ensures that. */
  //destinationClient.Authenticate( AuthenticationMethod.Ssl, VerificationFlags.None, null, DataChannelProtection.Clear );
  
  // Login to the destination server
  destinationClient.Login( "normal", "normal" );

  /* For a FXP transfer, only one client can be setup for passive transfer.
     The FxpServer enumeration allows to select either the source or destination client
     as the one that will be setup as passive.
    
     A FxpServer value is supplied to FtpClient.FxpCopy() */
  FxpServer passiveServer = FxpServer.Source;

  // Change the current folder on the source server to get to the file we want
  sourceClient.ChangeCurrentFolder( "normal1" );

  // Copy a file from the source server's current folder to the destination server giving the file a specific name
  FtpClient.FxpCopy( sourceClient, "tvDebug.log", destinationClient, "FxpCopy.xml", passiveServer );

  // Copy a file from a specific path on the source server to the destination server using the same name
  FtpClient.FxpCopy( sourceClient, "/SftpFolder5/Folder2/ntprint.inf", destinationClient, "ntprint.inf", passiveServer );

  // Copy a file from a specific path on the source server to a specific folder relative to the current folder on the destination server
  FtpClient.FxpCopy( sourceClient, "/SftpFolder5/Folder2/ntprint.inf", destinationClient, "Folder2/ntprint.inf", passiveServer );
}
finally
{
  if( sourceClient.Connected )
    sourceClient.Disconnect();

  if( destinationClient.Connected )
    destinationClient.Disconnect();
}
      ' Create a FTP client to control our source server
      Dim sourceClient As New FtpClient()

      ' Create a FTP client to control our destination server
      Dim destinationClient As New FtpClient()

      Try
        ' Connect to the source server
        sourceClient.Connect("localhost", 21)

'         FXP transfers cannot be performed over encrypted data channels. While it is ok
'         to encrypt the control channel, the data channel must remain clear. The DataChannelProtection.Clear
'         value ensures that. 
        'sourceClient.Authenticate( AuthenticationMethod.Tls, VerificationFlags.None, null, DataChannelProtection.Clear );

        ' Login to the source server
        sourceClient.Login("normal", "normal")

        ' Connect to the destination server
        AddHandler destinationClient.CertificateReceived, AddressOf AnonymousMethod1

        destinationClient.Connect("localhost", 10021)

'         FXP transfers cannot be performed over encrypted data channels. While it is ok
'         to encrypt the control channel, the data channel must remain clear. The DataChannelProtection.Clear
'         value ensures that. 
        'destinationClient.Authenticate( AuthenticationMethod.Ssl, VerificationFlags.None, null, DataChannelProtection.Clear );

        ' Login to the destination server
        destinationClient.Login("normal", "normal")

'         For a FXP transfer, only one client can be setup for passive transfer.
'           The FxpServer enumeration allows to select either the source or destination client
'           as the one that will be setup as passive.
'          
'           A FxpServer value is supplied to FtpClient.FxpCopy() 
        Dim passiveServer As FxpServer = FxpServer.Source

        ' Change the current folder on the source server to get to the file we want
        sourceClient.ChangeCurrentFolder("normal1")

        ' Copy a file from the source server's current folder to the destination server giving the file a specific name
        FtpClient.FxpCopy(sourceClient, "tvDebug.log", destinationClient, "FxpCopy.xml", passiveServer)

        ' Copy a file from a specific path on the source server to the destination server using the same name
        FtpClient.FxpCopy(sourceClient, "/SftpFolder5/Folder2/ntprint.inf", destinationClient, "ntprint.inf", passiveServer)

        ' Copy a file from a specific path on the source server to a specific folder relative to the current folder on the destination server
        FtpClient.FxpCopy(sourceClient, "/SftpFolder5/Folder2/ntprint.inf", destinationClient, "Folder2/ntprint.inf", passiveServer)
      Finally
        If sourceClient.Connected Then
          sourceClient.Disconnect()
        End If

        If destinationClient.Connected Then
          destinationClient.Disconnect()
        End If
      End Try
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

Reference

FtpClient Class
FtpClient Members
FxpPassiveTransfer Property
RepresentationType Property
TransferMode Property

Overview

Using the FXP Protocol