Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: Using wildcards to access SFTP directory

Thanks for the reply. There will definitely be more. Every day there are new files created so each day there new order/item pairs. For example, yesterday it may be order_034/item_229 and today it would be order_882/item_002. There will be multiple order/item pairs. Within each order/item pair, there will be multiple files of format File_YYYY_MM_DD

I need the logic to find all file_* that are within X days of today's date. This means looking at all order/item pairs. If X = 0 then that means only return order/item that equals to today's date. I forgot to include the X days part earlier. Sorry about that.

How would I implement this?

Thank you so much for your help!

Re: Using wildcards to access SFTP directory

You have to identify the order and item names first.
For example like this:
var opts = EnumerationOptions.MatchDirectories;
var order = session.EnumerateRemoteFiles("/", "order*", opts).First();
var orderPath = order.FullName;
var item = session.EnumerateRemoteFiles(orderPath, "item*", opts).First();
var source = RemotePath.Combine(item.FullName, "file_*");
transferResult = session.GetFiles(source, @"C:\Users\Me\To_Be_Processed\", false, transferOptions);

Untested + Assuming that there's always only one order and item.
If there are more, let us know how you want to handle that.

Using wildcards to access SFTP directory


I am creating a SFTP task in SSIS. I followed these steps:

The C# script works IF the file paths are explicitly stated. Below is excerpt that works:
TransferOperationResult transferResult;
transferResult =
    session.GetFiles("/order_000053922/item_000098300/file_*", @"C:\Users\Me\To_Be_Processed\", false, transferOptions);

However, the remote directory will have new order and item numbers so the numbers will change but it will always have order and item in the names. I need below to work:
TransferOperationResult transferResult;
transferResult =
    session.GetFiles("/order_*/item_*/file_*", @"C:\Users\Me\To_Be_Processed\", false, transferOptions);

I cannot use * like this. It complains. How would I code this so I can use * like noted?

Thank you