title: Spring SFTP Integration - Cannot Connect To Host Using known_hosts File
body: <p>I am attempting to build an application that makes use of Spring Boot and Integration to retrieve files from a remote system over SSH. It works just fine if I set the <code>allowUnknownKeys</code> property of the SessionFactory to true.</p>
  
  <pre><code>@Bean
  public SessionFactory&lt;LsEntry&gt; sftpSessionFactory() {
      DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
      factory.setHost("x");
      factory.setPort(22);
      factory.setUser("x");
      factory.setPassword("x");
      factory.setAllowUnknownKeys(true);
      // factory.setHostKeyAlias("x");
      // factory.setKnownHosts(
      //         System.getProperty("user.home") + File.separator + ".ssh" + File.separator + "known_hosts");
  
      return new CachingSessionFactory&lt;LsEntry&gt;(factory);
  }
  </code></pre>
  
  <p>However, if I set <code>allowUnknownKeys</code> to false and uncomment out the lines in the snippet above, a connection cannot be established. </p>
  
  <blockquote>
    <p>2019-01-21 08:55:05.536 ERROR 10680 --- [ask-scheduler-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessagingException: Problem occurred while synchronizing 'sftp-outbound' to local directory; nested exception is org.springframework.messaging.MessagingException: Failed to execute on
        session; nested exception is org.springframework.integration.util.PoolItemNotAvailableException: Failed to obtain pooled item</p>
  </blockquote>
  
  <p>The underlying cause is the fact that the "authenticity of the host" cannot be established, and it is wanting me to give permission to establish the connection. I understand this. However, my problem is why it is not reading/parsing the the known_hosts file correctly? The one I am passing to it is the one automatically generated and it works fine when I ssh into a system through the command line. Using breakpoints, I have verified that the application is finding and reading the correct <code>known_hosts</code> file. I can use the exact same credentials and connect through a bash shell without any prompt concerning the authenticity of the host. </p>
  
  <p>What am I missing?</p>
  
  <p>Thanks.</p>