BizTalk: using the SFTP and FTP Send adapter to download a file.

It is possible in newer versions of the SFTP and FTP adapter to download a file or list a directory using the Send adapters.

Date Entered: 09/17/2009    Last Updated: 07/29/2016

In some cases it is beneficial to be able to decide when to download a file and instruct the adapter to perform that action instead of relying on the receive location to poll at the specified interval. The SFTP and FTP adapters expose a way to do this through a solicit response port which you can use within an orchestration.

This allows you to create an orchestration where you can choose the files you want to download, and when, on the fly. Below are details on the two operations (downloading a file and listing a directory) using a solicit response port.

Listing the Directory

In your orchestration after referencing the SFTP or FTP adapter you can set the message context properties to configure the adapter. To specify that the adapter should list the directory set the Other property to ListDirectory=true. For instance:

Message_2 = Message_1; Message_2(nsoftware.BizTalk.SFTP.SSHUser) = "test"; Message_2(nsoftware.BizTalk.SFTP.SSHPassword) = "test"; Message_2(nsoftware.BizTalk.SFTP.SSHHost) = "server"; Message_2(nsoftware.BizTalk.SFTP.SSHAcceptServerHostKeyAcceptAny) = true; Message_2(nsoftware.BizTalk.SFTP.RemotePath) = "temp"; Message_2(nsoftware.BizTalk.SFTP.RemoteFile) = "*.txt"; Message_2(nsoftware.BizTalk.SFTP.Other) = "ListDirectory=true";

The solicit response port will return a message with a body containing an XML formatted representation of the directory contents. For instance:

size size size

Note: The SFTP adapter returns additional CTime and ATime elements representing the CreationTime and AccessTime. CreationTime is only supported on servers that support SFTP protocol version 4 or higher. To enable the adapter to use version 4 or higher you can set the Other property to "ProtocolVersion=4".

Downloading a File

Because a solicit response port can return only one message, you can only download one file at a time with the SFTP and FTP send ports. To do this you'll need to set the DownloadSingleFile configuration setting to true. For instance:

Message_2 = Message_1; Message_2(nsoftware.BizTalk.SFTP.SSHUser) = "test"; Message_2(nsoftware.BizTalk.SFTP.SSHPassword) = "test"; Message_2(nsoftware.BizTalk.SFTP.SSHHost) = "server"; Message_2(nsoftware.BizTalk.SFTP.SSHAcceptServerHostKeyAcceptAny) = true; Message_2(nsoftware.BizTalk.SFTP.RemotePath) = "temp"; Message_2(nsoftware.BizTalk.SFTP.RemoteFile) = "test.txt"; Message_2(nsoftware.BizTalk.SFTP.Other) = "DownloadSingleFile=true";

Note: You can also set DeleteAfterDownload in the Other property to delete the file on the server once the download is complete. This can be done by setting one configuration setting per line in the Other property:

Message_2(nsoftware.BizTalk.SFTP.Other) = "DownloadSingleFile=true\r\nDeleteAfterDownload=true";

Note: It is also possible to download multiple files with the send adapters. To do this you can not use a solicit response port. You must use a one way send port. In that case set the Other property of the adapter to "Download=True" and "LocalFile=C:\YourDirectory" (one setting per line).


We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.