Ant scp task failure

user617228 picture user617228 · Jun 15, 2011 · Viewed 21.7k times · Source

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

  1. downloaded jsch-0.1.44.jar and copied to lib folder of Ant
  2. set the path and every thing

My buildfile is:

<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 resolve this?

Answer

martin clayton picture martin clayton · Jun 15, 2011

According to the Ant scp task docs, trust attribute:

This trusts all unknown hosts if set to yes/true. Note If you set this to false (the default), the host you connect to must be listed in your knownhosts file, this also implies that the file exists.

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