Reputation: 31
Is it possible to invoke sftp outbound endpoint, and send a file, through the code? I have a reference to a File object in java code (in a custom transformer), and I want to invoke sftp outbound endpoint and pass that File reference. Is this doable? Thanks.
Upvotes: 0
Views: 867
Reputation: 33413
Pass it a FileInputStream
, that should work.
muleContext.getClient().dispatch("sftp://...", new FileInputStream(file), null);
If not, you'll have to pass it a byte[]
.
Note that dispatch
is asynchronous: the call will return immediately while the SFTP communication occurs. if you want to wait until it's done, use send
with a time-out as last parameter.
Since you have several SFTP connectors configured, you'll have to specify the connector name in the URL. Supposing you want to dispatch using SFTP_Upload_Connector
, you'll have to use:
muleContext.getClient().dispatch("sftp://...?connector=SFTP_Upload_Connector", new FileInputStream(file), null);
If you want to set a particular destination file name, pass it as a property named filename
in the properties map, for example using:
muleContext.getClient().dispatch("sftp://...?connector=SFTP_Upload_Connector", new FileInputStream(file), Collections.singletonMap("filename", "somen_ame"));
Upvotes: 1