Posted on Leave a comment

Create a scheduled task fetch files from SFTP in Biztalk

Highlights – Biztalk 2013, Biztalk Scheduled Task Adapter, Visual Studio, IIS, C# WCF Service with WinSCP Nuget package

Recently I had a request for a Biztalk solution that gets files from a SFTP folder and process in a Biztalk receive location. It was easy just create a SFTP receive location. However here is a twist. The files can only be picked up once a week. Problem was that the receive location picked up files as soon as it landed there.

The solution was obvious a scheduled task was required. My first thought was to create a C# script and run it on a task scheduler that would pick the files from the SFTP and place it on the receive folder location for Biztalk. But then if that possiblity exists in Biztalk why not use it. The latest version of Biztalk as of now is 2020 which has that functionality. However I was using 2013.

There is a way to do this in Biztalk 2013, by using the scheduled task adapter in Biztalk. Then pass that call to the send port that calls a WCF service that uses an SFTP client like WinSCP. The source code are provided in the bottom of this tutorial.

Here I describe the steps to complete that task.

ReceivePort –> ReceiveLocation runs on schedule–> SendPort –> WCFService –> WinSCP–>Transfer files to another receive location

I created a schema in biztalk for the purpose. This is to associate the XML in the receive location to the Send Port

Create a receive location and a scheduled transport type. From the drop-down in the type select the schedule adapter. If you have not the schedule transport type, you would need to download and add Biztalk Scheduled Task Adapter and install it. I have version 5.0.

In the properties section, go to Task tab and find the task

In the task section choose the TaskComponents.dll. We want to create a

From there use the XML string provider, because we want to send an XML to the Send Port in the later scenario.

In the XML string toolbox we create a simple xml string like the following, remember the namespace. We require this in the send port and WCF applciation.

<?xml version="1.0"?>
<ns0:Call xmlns:ns0="http://NirjalBiztalkApp.CallSFTP"/>

To run the task on a schedule, on the schedule tab. Configure how often you want the scheduler to run. This for example will run every 15 seconds.

Next we go ahead and create the C# WCF service in Visual Studio. Later we are going to create a send port that calls this WCF service.

Next have download WinSCP nuget package to get files from SFTP.

After installation and setting up publish the WCF service or run it and browse to the .svc address.

Now we copy the soapAction from the wsdl file. This will be later used in the Send Port.

Now create a send port that associates to the receive port created earlier. In the filter section, for example I used the ReceivePortName. Other properties can also be used.

In the send port find the WCF-Custom binding for type, binding I created a HTTP binding. Provide the address to the WCF service in the Address for the SOAP action. Provide the SOAP action copied earlier from the wsdl.

Start the Biztalk application and see what happens. If everything goes as planned the application will run every 15 seconds and call the WCF service. Thats all to it. If you like the source files to the project I have provided them in GitHub Feel free to use it and let me know if you have any comments.

https://github.com/coolnk/BizalkWCFScheduler

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.