cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Multi-file read / multi-file write

vcocco
New Contributor II

Hi there,
I have a need where I have to read multiple files from an sftp site and write all of those files (if they exist) to multiple file names. Would the binary reader fit the bill here?
Iโ€™m familiar with the multi-file read and the directory browser. I can successfully use those snaps to read whatโ€™s on the remote sftp server.
Right now Iโ€™m using the File Readerโ€™s Folder/File box in Settings to do something like this:
sftp://transmissions-uat.testsite.com/Outbound/Encrypted

It reads all of the files in the Encrypted folder. Attached to this snap is the File Writer snap which seems to write the latest file to my file name. Is there a way to write all of the files to multiple file names? Iโ€™ve seen some mention of the Binary Router snap. Would this be the way to go?

Thanks,
Vin

7 REPLIES 7

tlikarish
Employee
Employee

The way most binary snaps function is to write the binary stream with a metadata document about the contents โ€“ kind of like the header in an HTTP request. For example here is some preview data of a MultiFileReader snap Iโ€™ve hooked up:

image

The content-location field will give the path to the file โ€“ the full path. This can be used in a FileWriter snap to write out each file with the same file name in a new location. Hereโ€™s an example of an expression that would do that:

image

Hereโ€™s the expression if you want to copy/paste and fill in your server specific information.
"sftp://transmissions-uat.testsite.com/Outbound/Encrypted/" + $['content-location'].split('/').pop()

I put together an example pipeline that hopefully will be useful for demonstrating how this all fits together.

multi-file-read-write_2019_01_23.slp (3.7 KB)

vcocco
New Contributor II

thank you very much for this example!
I will try it out on my org and let you know if I have any questions.

Thanks again,

Vin

vcocco
New Contributor II

Hello Again,
The โ€˜content-locationโ€™ code in File Write worked for me. Using the wild-card character in File Read I was able to narrow down to specific files I wanted and was able to do an โ€˜smbโ€™ write to our network folder.

Earlier, I tried to import your example Pipeline but got this error:

SnapLogicImportError

I originally downloaded the .slb file but SnapLogic Import didnโ€™t see it on my Mac. I compressed it (turned it into a zip file) and the Importer was able to see it but gave me the error message.

Also: Iโ€™ve been testing out the Email Sender snap to send out an email notifying certain users that a file or files exists on the network folder. I just want to send out an email if and only if the File Reader finds files on the sftp site. Could you point me to some examples?
Thanks again for your assistance,
Vin

To upload the example, go to Designer and click on this icon. That will enable you to import a single pipeline.

09%20PM

For the email sender, if you were going to do it in the same pipeline you could use the binary router to duplicate the stream, combine the results into a single document, and then pass that to the Email Sender, like this:

image

Might make it simpler to implement this in a separate pipeline though. Then youโ€™d just have the Reader โ†’ Binary To Doc โ†’ Aggregate โ†’ Email Sender.

Hopefully that helps you get started with the next step.