How to make ANT and SCP play nice

abargnesi Apr 18, 2008 Computers
We all want to use ANT so chances are that you'll use the SCP task at some point. Now what you may not know is that this task relies upon the Java Secure Channel library, referred to as jsch, created by JCraft.

We all want to use ANT so chances are that you'll use the SCP task at some point. Now what you may not know is that this task relies upon the Java Secure Channel library, referred to as jsch, created by JCraft. In ANT 1.7.0 (latest release as of this writing) it recommends to use version 0.1.29 of jsch, but the latest from JCraft is 0.1.36. Here is how to tell ANT to use a different version:

  1. cd to $ANT_HOME/lib
  2. vi libraries.properties
  3. Edit jsch.version=0.1.29 to read jsch.version=0.1.36
  4. Make sure the jsch jar in $ANT_HOME/lib stays named jsch-0.1.36.jar

Voila! Now the SCP task can be used since you satisfied its only dependency. Will that work? Well sorta, if you don't mind the SCP task hanging. To see more verbose output, as the scp task is executing, make sure you add verbose="true" to the tag. 

Don't fret, this is a known bug. See this ant buzilla issue for reference. This issue relates to a missing out.flush(); in the ScpToMessage class when copying directories to a remote host.

A simple fix!  Hope at last!

Just get the Source Distribution of ANT and modify the file src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java. You will need to add out.flush(); after line 211. Lines 209 - 213 will look as follows:

waitForAck(in);
sendDirectory(directory, in, out);
out.write("E\n".getBytes());
out.flush();
waitForAck(in);

Now build ant and move the new ant-jsch.jar to $ANT_HOME/lib and you will be all set.

No more hanging!  Enjoy!

What did you think of this tutorial?
- 1
0 CommentsAdd a Comment
Name
Comment
  • Views : 1495
  • Comments : 0
  • Rating : - 1
  • Last Updated : Apr 18, 2008