Over a million developers have joined DZone.

How to Solve Mule SFTP Connector Algorithm Negotiation Fail Exception

DZone's Guide to

How to Solve Mule SFTP Connector Algorithm Negotiation Fail Exception

This quick tutorial will show you how to resolve issues with the Mule SFTP connector connecting to remote file locations.

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

This article is the resolution of the Mule SFTP connector when connecting to remote file locations.

The configurations details are below:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
       xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd">
       <sftp:connector name="SFTP" validateConnections="true" doc:name="SFTP" />
       <flow name="sftpflow">
             <sftp:inbound-endpoint connector-ref="SFTP" host="host_ip" port="22" path="File Loactions " user="USERNAME" password="PASSWORD"
                    responseTimeout="10000" doc:name="SFTP" >
            <reconnect count="3"/>
             <logger message="Able to read file :- #[payload]" level="INFO" doc:name="Logger" />

The exception will be:

com.jcraft.jsch.JSchException: Algorithm negotiation fail
       at com.jcraft.jsch.Session.receive_kexinit(Session.java:583) ~[jsch-0.1.51.jar:?]

The SFTP connector for Mule has the in-built support jsch-0.1.51.jar. So, while connecting to secure file locations through the SFTP connector, the com.jcraft.jsch.JSchException: Algorithm negotiation fail exception is thrown.

In the JSch.class for jsch-0.1.51.jar, for the KEY -->"kex," it does not have the value "diffie-hellman-group-exchange-sha256" for connecting to the remote location securely. The sha256 exchange pattern is required, which is there in the jsch-0.1.54.jar file. But for 3.6.2/3.7.1 and 3.8.1 runtime versions, the in-built third party jsch-0.1.51.jar has been used.

The Workaround

 Override the KEY "kex" and add the value diffie-hellman-group-exchange-sha256.

The following block should be added in the Static block:

configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");


public class JSchKeyConfig {
 static {
  Properties configuration = new Properties();
  configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");

Inject the JSchKeyConfig through Spring beans. 

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

mule 3.7 ,java ,mule ,tutorial ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}