A colleague of mine approached me asking what would be the easiest approach to download a single file from a FTP location that when the file name is changing frequently without any logical pattern.

My immediate thought was to use an empty ForEach Loop Container because it can just iterate over files, so even though we are dealing with one file it would be able to capture its name in a single hop. Now to the specifics.

As an aside, it was an existing package that used to consume a fixed name file, but the requirements have changed. To glance ahead, the package after it was completed looks like:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now the specifics: so the FTP component is simply set to download the entire contents of the FTP directory (the file there just keeps updating). Thus nothing special is in there.

The trick is in linking this FTP Task to the ForEach Loop Container! Inside this ForEach there is nothing and its setup is literally trivial:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

It uses a file enumerator and it is set to go to a specific directory (blurred) to get all files with the .csv extension. So far a no brainer. Next setting to apply is to map the file name retrieved to a variable:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 This way we capture the file name.

At the next or any subsequent stage we are able to consume this file through its name and location.

Since the package stored this file aside as a copy by design we have a File System Task connected next to the ForEach Loop to copy it:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This is it! 

I guess if we need to handle multiple files this package is as easily modifiable to just move those outside components into the ForEach Loop.