SFTP Adapter is a new adapter added to the built-in adapters in BizTalk Server 2013. I explained how to use SFTP adapter in article BizTalk Server 2013: How to use SFTP Adapter. In that article I explained how to prepare SFTP testing environment and how to configure the SFTP adapter at design time. In this article I will walk-through in how to configure SFTP send port dynamically at run-time.


You have an orchestration that sends messages to a specific customer via SFTP adapter. However, your integration middleware start to be expanded and start to have multiple types of customers that need to receive messages in different SFTP addresses. So, how we can update our orchestration to enable it to send messages to dynamic addresses.


We need to create a dynamic send port and configure it at run time. Dynamic ports allow the physical location of a physical send port (one-way or solicit-response) to be determined at run time. The ability to specify the transport protocol and address at run time allows for the flexibility of routing messages depending on message content or message context. We can configure the send port to be a dynamic within the orchestration and we can save and retrieve properties of SFTP adapter configuration information from our configuration DB or Business Rule Engine (BRE) 

Step By Step Implementation

  • Create a source schema (CustomerInfo) as shown in figure 1

    Figure 1. CustomerInfo Schema Structure

  • Create a schema for BRE settings as shown in figure 2, in my demo I just want Address, username and password we can add more if you want to use digital certificates

    Figure 2. Sftp Bre Schema Structure
  • By using Business Rule Composer create the SFTP Dynamic Policy and rule for each customer as shown in Figure 3, 4, 5 then Publish and Deploy policy

    Figure 3. Customer A Rule

    Figure 4. Customer B Rule

    Figure 5. Customer C Rule

  • Create an orchestration that processes a message and send it to a dynamic port, I created a sample orchestration as shown in figure 6

    Figure 6. Business Process Orchestration
  • Define the following variable and messages as the following table
    Message / Variable Identifier Type Comments
    Message msgIn TechNetWiki.DynamicSftpPort.CustomerInfo The incoming message
    Message msgOut TechNetWiki.DynamicSftpPort.CustomerInfo The outgoing message
    Message msgSftpBre TechNetWiki.DynamicSftpPort.SftpBreSchema The Sftp Bre info message
    Variable varSftpBreXmlDoc System.Xml.XmlDocument A variable to load msgSftpBre message
  • Inside Assign_SftpBre assignment shape we need create xml document as the following code
    varSftpBreXmlDoc.LoadXml(@"<ns0:SftpInfo xmlns:ns0='http://TechNetWiki.DynamicSftpPort.SftpBreSchema'>
    msgSftpBre = varSftpBreXmlDoc;

  • Inside AssignDynamicSftpInfo assignment shape we will set the values retrieved from BRE to fill the msgOut and DynamicSFTPPort properties
    DynamicSFTPPort(Microsoft.XLANGs.BaseTypes.Address)=msgSftpBre.Address + "%MessageID%.xml";

  • Create a send port in configuration wizard Set Port binding to Dynamic as shown in figure 5

    Figure 7. Set Dynamic Port Binding
  • Deploy your project and create file receive port/location, then configure orchestration then enlist and start the application.
  • Test the solution by adding some sample files with different customer id. In this demo I created three folders A,B,C inside the SFTP server to test the output messages.
  • You can check BizTalk Server 2013: How to use SFTP Adapter to know how to prepare sftp testing environment

Sample Code

You can find the source code belonging to this article on MSDN Code Gallery:BizTalk Server 2013: How to configure SFTP Send Port Dynamically


In this article, we showed how to create a dynamic sftp send port inside orchestration and how to configure it at run time by using Business Rule Engine.

See Also

Read suggested related topics: Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.