Using wildcards to access SFTP directory

Advertisement

f4932
Joined:
Posts:
2

Using wildcards to access SFTP directory

Hi

I am creating a SFTP task in SSIS. I followed these steps:
https://winscp.net/eng/docs/library_ssis

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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

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.

Reply with quote

f4932
Joined:
Posts:
2

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!

Reply with quote

Advertisement

You can post new topics in this forum