0 votes
by (150 points)
edited

I am trying to download multiple files from the SFTP server.

I am having trouble with the GetFiles() Method, where it works in some instances, but not in others.

I Have a main directory, for example Lets call it Main, and it has 3 subdirectories under it, Dir1,Dir2 and Dir3. Each of those subdirectories have .dat files in them.

The following command is NOT downloading any of the .dat files:

client.GetFiles("/Main/*.dat", "c:\temp", SftpBatchTransferOptions.Recursive)

The following commnand IS downloading the .dat files (only from Dir1):

client.GetFiles("/Main/Dir1/*.dat", "c:\temp", SftpBatchTransferOptions.Recursive)

Why isnt the first example not getting any of the .dat files from any of the subdirectories. It does not seem like the recursive option is working properly?

I even tried using the SFTP Batch Transfer Sample provided with the download, with the same results.

Applies to: Rebex SFTP

1 Answer

0 votes
by (144k points)
edited

Try using SftpBatchTransferOptions.XCopy instead of SftpBatchTransferOptions.Recursive. It looks like that is the recursive mode you need!

SftpBatchTrasferOptions.Recursive: Operation is recursive. Files in the specified directory and all subdirectories are to be transferred. If wildcards are used, all files and subdirectories that match the wildcard are transferred (in case of subdirectories, this means that if a subdirectory name matches, all the files and sub-subdirectories in it are transferred).

SftpBatchTrasferOptions.XCopy: Operation is recursive. Files in the specified directory and all subdirectories are to be transferred. If wildcards are used, all files in the current directory (or any of its subdirectories) are transferred if they match the wildcard (this means that all subdirectories are traversed).

by (150 points)
I tried using the Xcopy mode, it copies all of the folders as well, is there an option to only download the files?
by (144k points)
This is a known limitation of this mode. Would you like to download all the files into a single folder? It looks like some kind of an ability to change the suggested target path for each item would be helpful. We will consider this for one of the next releases. In the meantime, the recommended workaround is to iterate through the downloaded directory tree, move all files to their desired location and remove unwanted directories.
by (150 points)
Yes, I would like for it to download to a single folder.
...