Multi-file operations: Converting code to use the new API

0 votes
asked Mar 27, 2012 by Rebex KB (8,210 points)
edited Mar 27, 2012

What is the difference between PutFiles() and Upload(), GetFiles() and Download() methods in Rebex FTP/Rebex SFTP (Ftp and Sftp objects)?

1 Answer

0 votes
answered Mar 27, 2012 by Rebex KB (8,210 points)
edited Mar 27, 2012

In March 2012, a new API for multi-file operations was released. The common enum Rebex.IO.TraversalMode was introduced to be used instead of Rebex.Net.FtpBatchTransferOptions and Rebex.Net.SftpBatchTransferOptions enums.

The old API methods are PutFiles and GetFiles in Rebex FTP/Rebex SFTP (Ftp and Sftp objects).

The new API methods are Upload and Download in Rebex FTP/Rebex SFTP (Ftp and Sftp objects).

There are three major changes:

  1. The values of the FtpBatchTransferOptions and SftpBatchTransferOptions are now represented by the TraversalMode and LinkProcessingMode enums. TraversalMode can be specified within the call of the relevant multi-file method. LinkProcessingMode can be set globally using Ftp/Sftp object’s Settings.MultiFileLinkMode property.

  2. The default (zero) value of TraversalMode is Recursive while the default value of FtpBatchTransferOptions and SftpBatchTransferOptions is NonRecursive.

  3. The behavior of NonRecursive value has changed. The new API exactly matches the specified pattern, while the old API behaves differently when the pattern matches a directory. A value of MatchFilesShallow in the TraversalMode enum makes it possible to achieve the original behavior. See the following example:

Let's have a directory named "root_dir" with two files "file1.txt" and "file2.pdf" and one subdirectory "subdir" containing the file "subfile.txt". The following table describes the behavior of GetFiles and Download methods (and the same applies to PutFiles and Upload methods):

Method call with wildcardBehavior
GetFiles("root_dir/*", NonRecursive)Creates "file1.txt" and "file2.pdf".
Download("root_dir/*", NonRecursive)`Creates "file1.txt" and "file2.pdf" and "subdir" with no content.
Download("root_dir/*", MatchFilesShallow)Creates "file1.txt" and "file2.pdf".
Method call without wildcardBehavior
GetFiles("root_dir", NonRecursive)Creates "root_dir" with the "file1.txt" and "file2.pdf".
Download("root_dir", NonRecursive)Creates "root_dir" with no content.
Download("root_dir", MatchFilesShallow)Creates nothing at all (because "root_dir" is not a file).

To convert old API’s methods using NonRecursive to the new API, the following changes have to be made:

// a) wildcarded path
GetFiles("source_directory/*", "target_directory", BatchTransferOptions.NonRecursive)
// becomes  
Download("source_directory/*", "target_directory", TraversalMode.MatchFilesShallow)

// b) directory path    
GetFiles("source_directory", "target_directory", BatchTransferOptions.NonRecursive)
// becomes  
Download("source_directory/*", "target_directory/source_directory", TraversalMode.MatchFilesShallow)

// c) file path
GetFiles("source_file", "target_directory", BatchTransferOptions.NonRecursive)
// becomes  
Download("source_file", "target_directory", TraversalMode.MatchFilesShallow)
...