0 votes
by (8.4k points)

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
by (8.4k points)

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)