Overview
SFTP is a file transfer protocol used to securely transfer files over networks, such as the Internet. In the integration landscape, SFTP is frequently employed to connect different systems, where the receiving system expects data in the SFTP location for further processing. In this article, we will guide you through the step-by-step procedure to set up a connector and use it to retrieve files from an SFTP server in webMethods.io.
Prerequisite :
- You should have access to the WebMethods.io integration environment.
- Basic knowledge of Webmethods.io.
- Basic knowledge of SFTP.
Collect SFTP server details
For this demo, we’ll utilize a free online SFTP server. If you have your own SFTP server accessible over the internet, you can use it for this project. Alternatively, you can click here to obtain details for a free read-only SFTP server. Please note that we are not endorsing any specific service, and it is your responsibility to choose what best suits your needs.
SFTP Connector Configuration
- Navigate to the Webmethods.io environment.
- Click on the plus icon and create a project.
- Navigate to the project that you have created now.
- Navigate to the ‘Connector’ tab and on the right-hand side, you will see a search icon. Click on it and search for “SFTP”.
- Please click on the SFTP icon and configure the account with the SFTP information you collected in the previous step, then click the ‘Add‘ button.
- Once you click on the ‘Add’ button it should create the connection successfully, if not please let me know in the comment section.
Connect to SFTP server using SFTP client
- You should have one SFTP client installed in your system, for this project, we will be using the WinSCP application to connect to the SFTP server and view the files that are available on the server.
- Once you open the WinSCP Application, it will ask you to connect to an SFTP server else click on the ‘New Tab‘ to connect to a new SFTP server.
- Fill the SFTP server details that you have collected from the above step and connect to the SFTP server.
- Once connected to the SFTP server, you will discover a ‘readme.txt’ file available in the root directory. We will proceed to read the file’s content from the SFTP server using a flow service in webMethods.io.
Read File Using SFTP connector
- Navigate to the webMethods.io environment and get into the project where we have created the SFTP connector.
- Navigate to the ‘Integrations’ tab and click on ‘Flow Services’ option.
- Click on the plus icon to create a new flow service and give it a meaningful name.
- In the flow service, invoke ‘Secure File Transfer Protocol SFTP‘ and select the ‘get’ option in the action menu. Then, choose the connector that we created in the previous step from the account dropdown menu.
- Click on the “Edit Pipeline” button and hardcode the value of ‘remoteFile‘ to ‘/readme.txt‘. In a real-life project, you would typically provide the full path along with the file name to read the content.
- Invoke the ‘StreamToString‘ service and map the ‘contentStream‘ to the ‘inputStream‘ to convert the stream object to a string format.
- Now for testing purposes, we need to log the file content so invoke ‘logCustomMessage‘ and map ‘string‘ to ‘message‘.
- We have completed the development phase. However, it’s essential to note that for demonstration purposes, we have not implemented the try-catch mechanism. In real-life projects, it is crucial to implement this mechanism to effectively handle exceptions.
- Now run the flow service, and you will notice the file content on the screen.
Hope you have enjoyed this article, Cheers!