Ant scp task error

I have one requirement: copy local files to the remote system. I have done the following:

  • downloaded jsch-0.1.44.jar and copied to the lib folder from Ant
  • set the path and all

My build file:

<project name="ImportedBuild" default="all"> <target name="copyFileToRemote"> <echo>2222222222 copyFileToRemote Examples:::::::::::::</echo> <scp file="sample.txt" todir="${username}:${password}@${hostname}:/shared"/> </target> </project> 

When I run Ant, I get this error:

 BUILD FAILED com.jcraft.jsch.JSchException: reject HostKey: 10.184.74.168 at com.jcraft.jsch.Session.checkHost(Session.java:712) at com.jcraft.jsch.Session.connect(Session.java:313) at com.jcraft.jsch.Session.connect(Session.java:154) at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:212) at org.apache.tools.ant.taskdefs.optional.ssh.Scp.upload(Scp.java:291) at org.apache.tools.ant.taskdefs.optional.ssh.Scp.execute(Scp.java:203) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288) ... etc ... 

Any ideas how to solve this problem?

+13
source share
2 answers

According to Ant scp docs task , trust attribute:

It trusts all unknown nodes if set to yes / true. Note. If you set this to false (the default), the host that you are connecting to should be specified in your knownhosts file, this also implies that the file exists.

The trust attribute is not used in the task call, so it seems that the host (10.184.74.168) is not in your known hosts file. Suggest adding trust="true" or adding the host to the knownhosts file.

+33
source

Make sure your ~/.ssh/known_hosts uses un-hashed hostnames; if the lines begin with |1|base64data... , JSch is unable to |1|base64data... them. Create strings of the format hostname[,hostname|ip]* ssh-keytype base64data...

See man 8 sshd for the exact format known_hosts and tips on where to find the public host key.

+3
source

All Articles