SFTP Configuration and Implementation in webmethods

What is SFTP?

  • SFTP(Secure File Transfer Protocol) is a protocol used to transfer files between computers over a network.
  • SFTP is used because it provides strong security features, it encrypts data transmission and makes it difficult for unauthorized parties to intercept and read the data.
  • It allows us to implement authentication using either user name and password or public-key authentication to protect data against unauthorized access.

 

Setup SFTP Server :
As part of this article, we will need the SFTP server to transfer files to and from our local file system, so we need to set up the SFTP server first.

  • Navigate to rebex.net and download the tiny sftp server.

     

  • Once the tiny SFTP server is downloaded, extract the .zip file in your preferred location.
  • Open the folder where you have extracted the .zip file and notice the RebexTinySftpServer application.

     

  • Double-click on RebexTinySftpServer application, it will open the application and show you the button to start the SFTP server. click the start button.

     

  • Once you start the SFTP server we can connect to the SFTP server using the host and credentials shown in the above screenshot.
  • Now open any SFTP client like WinSCP, FileZilla, etc. to verify the SFTP connection.
  • Open the WinSCP application and click the ‘New Session’ button.

     

  • Once you click on the ‘New Session’ button, it will ask you to fill in the SFTP server host and credentials to connect and fill in the details you got from the tiny SFTP server.
  • Once you log in using the SFTP credential, you will notice only one text file available in the directory.
  • Create a new directory in the root directory with the name ‘SFTPDemo’, this directory we will use in our flow service.

 

SFTP Configuration in Integration Server :

In webmethods, we need to configure both the Server alias and user alias to work with SFTP. 

 

  • Server Alias :
    • Server alias can be created using the SFTP host details.
    • For one SFTP server alias, we can have multiple user alias.
    • SFTP server alias is necessary to be created for user alias.
  • User Alias :
    • User aliases can be created using the server alias and the user credentials.
    • A user alias is needed because, for a particular SFTP directory, we may have different users with different levels of access like read, write, or both so based on the access level and the requirement we can create the user alias and use the same while performing SFTP file transfer.
  • Configuration :
    • Open Integration server.
    • Click on the ‘SFTP’ option under the ‘External Servers’ tab and then click on the ‘Create Server Alias’ option as shown in the screenshot.

    • Now fill in below SFTP details and click on the ‘Get Host Key’  button and save the server alias.
      • Alias: Give a unique server alias name.
      • Host Name or IP Address: Provide the hostname or IP address of the SFTP server.
      • Port Number: Port number of the SFTP server.
      • Proxy Alias: If you have any proxy alias already configured and you want to use it then select the same here.

         

    • Once you’ve saved the server alias, the next step is to create a user alias for the same server.
    • Click on the ‘User Alias Settings’ on the ‘SFTP’ page.

       

    • Now it will open the ‘User alias settings’ page, click on the ‘Create User Alias’ option.
    • Now fill in the below details for the user alias and click the Save changes button.
      • Alias: Unique alias name for the user.
      • User Name: The user name for the server.
      • Authentication Type: Choose Password, you can also choose the Public Key if you have the information.
      • Password: Password for the user.
      • SFTP Server Alias: Select the server alias that we created earlier.
      • Other details you can adjust based on your requirements.

         

    • We have created the user alias now, click the test button to verify if the connection is set up correctly.

       

    • Congratulations!! We are done with the connection set up now.

 

SFTP Implementation :

  • Create a package with the name ‘HG_SFTP_Demo’ and create the below package structure.

     

  • In the services folder create a flow service with the name ‘putFileInSFTP’.
  • Invoke ‘pub.client.sftp:login’ flow service and perform the below mappings.
    • useralias: SFTP user alias that we created earlier.
    • reuseSession: Set it true if you want the IS to use the existing session for the user alias and if no existing session is available the IS will create a new session and share the session key with you, the default value is false.
    • sftpConfigurationParameters : This you can fill if you don’t have the SFTP connections configured already else leave it.

       

  • Invoke ‘pub.client.sftp:put’ and perform the below mappings.
    • sessionKey: session key generated from the previous step
    • contentStream : If you have the content that you want to store in the form of a stream object then map the same here.
    • localFile : If you want to transfer the file from your local directory then map the full file path(‘D:/SFTP/Local/HarmoniGate.txt’).
    • remoteFile : Provide the remote file path(‘/SFTPDemo’).
    • mode : If you want to append the connect to a file or replace based on that you can configure the mode.

       

  • Invoke ‘pub.client.sftp:logout’ and map the session key to close the session.
  • Now we are done with the first service development to put the file into the SFTP server so let’s run it and see if we are getting the expected result.
  • Congratulations !! We did it😀.

     

  • Now we have created the flow service to transfer files from our local drive to the SFTP server, we can also download the file from the SFTP server to our local drive and perform the same using ‘pub.client.sftp:get’ service.
  • Please check out the services listed in ‘pub.client.sftp’ folder in WmPublic package.

Hope you have found this article useful, please drop a comment if you have any questions regarding the article or if you need any specific article related to any integration area.

Click below download button below to download the project source code.

 

2 thoughts on “SFTP Configuration and Implementation in webmethods”

  1. make a blog on webmethods Interceptor , how we can implement it and how to configure to Integration, Server the purpose is that ,whenever we invoke a a REST or SOAP API it will not generate a log sorequirement is that we have to generate it.

    Reply

Leave a Comment