Tom Philippi · Feb 16, 2017

Write files to different directories with from one EnsLib.File.OutboundAdapter

I have one Ensemble EnsLib.File.OutboundAdapter which has several methods, each writing a different file. In my Ensemble Production I have configured this FileAdapter to write to a certain directory, but i'd rather have each method write to a different (sub)directory instead of writing all files to the same directory. How can I achieve that without splitting the methods into different business operations?

The current code just sets the filename and the output:

set tSC = ..Adapter.PutString(filename,output)



0 367
Discussion (3)1
Log in or sign up to continue

Filename is appended to directory, so if you have a directory: /tmp/ you can call

set tSC = ..Adapter.PutString("old/plan.txt",output)
set tSC = ..Adapter.PutString("new/plan.txt",output)

and it should produce two files /tmp/old/plan.txt and /tmp/new/plan.txt in two different subdirectories. of /tmp

I guess this means that if you code things to allow the requester to specify the filename you may wish to take precautions against a directory escape exploit.

From a technical point Eduard mentioned the most straight forward way.

Another option would be to subclass EnsLib.File.OutboundAdapter. Having only one Put* call.

There for you may introduce a SecondFilePath setting. Overwriting the Put* methods using ##super() could then easiliy produce more than one filecopy.