SFTP Upload HL7

This tutorial will cover receiving an HL7 message over HTTP and uploading it over SFTP to an AWS Transfer Server.
1. Download and extract the WinSCP dll and exe here.
2. Copy them into the Custom Libraries directory of your Integration Host Server installation (Usually found at C:\Program Files (x86)\Popokey\Integration Host Server\Custom Libraries)
3. Open up the client and create a new workflow. Select HTTP receiver, use an open port and right click to paste a sample message in the message template window.
4. Now add a new activity to your workflow by clicking the arrow underneath your HTTP receiver on the left side of the workflow designer.
5. Select 'Run Code' for the activity type and paste in the below code.

#r "C:\Program Files (x86)\Popokey\Integration Host Server\Custom Libraries\WinSCPnet.dll" // location of your WinSCPnet dll

System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
string message = activityInstance.Message.Text;
writer.Write(message);
writer.Flush();
stream.Position = 0;
string filetype = (".hl7");
string filename = workflowInstance.GetVariable("CurrentDateTime");  // can be used to get any variable
WinSCP.SessionOptions sessionOptions = new WinSCP.SessionOptions
    {
        Protocol = WinSCP.Protocol.Sftp,
        HostName = "myftpserver.com",
        UserName = "MyUser",
        SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxxxxxxxxxxxxxxxxxx",  // it's important that your fingerprint be in this format
        SshPrivateKeyPath = @"path\to\my\key.ppk",  // the path to your private ssh key must be .ppk
    };
using (WinSCP.Session session = new WinSCP.Session())
    {
        session.Open(sessionOptions);
        session.PutFile(stream, filename + filetype);
    }
Should you have difficulty setting up the session options we highly reccomend downloading the WinSCP client and following their documentation for exporting sessions to code.

7. Click the save and close button! Your workflow should now be operational so try sending it some messages to test it out.

This demo covers a general use case for an FTP sender inside of Integration Host but can be applied to any type of message from any source. Simply use it as a guide to shape the solution to your use case.

Download HL7 Soup and Integration Host from our downloads page.

Return to Tutorials Directory