Hi All,

Hope you are all well!

I’m currently working on an task that involves sending files to a sftp server 
but instead of using credentials I am required to use an ssh private key for 
authentication.

I have already proven that connection with the private key is successful via 
command line :

sftp -i <path_to_private_key> username@hostname

…so I know that there is no issue with the privateKey itself!

We store the public key in AWS Secrets manager and this is injected into our 
application via Spring Cloud’s AWS Secrets Manager config starter. This is 
injected into SpringBoot’s application.properties. I’ve added debug logging to 
ensure there is no issue with the injecting. That value then gets stored as an 
exchangeProperty and converted into a Byte Array and pass it to the sftp 
command:

.to(“sftp://{{sftp.hostname}}:{{sftp.port}}/{{sftp.root.folder}}{{sftp.infolder}}?username={{sftp.username}}&privateKey=${exchangeProperty.sshPrivateKey}”)

When we trigger this route and the above line is executed we get the following 
error:

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot 
connect to sftp://gbt...@glue.brickftp.com:22
…
Caused by: com.jcraft.jsch.JSchException: invalid privatekey

After a bit of investigation I came across this StackOverflow 
article<https://stackoverflow.com/questions/67937961/apache-camel-sftp-jschexception-invalid-privatekey-b7c033a39-with-openssh>
 and noted that put private key was an openssh key so took the user Matthias 
Wiedemann’s advice and switch JSCH library and attempted to connect again but 
with similar failure.

Was hoping that someone may have experienced something similar before and may 
be able to help out.

Kind Regards
Simon
Simon Loy
Solutions Developer

simon....@uktv.co.uk



[https://s3-eu-west-1.amazonaws.com/uktv/UKTVeMailSig.jpeg] 
<http://www.uktv.co.uk/>

Reply via email to