Ant SCP/SSH Task Hangs Or Never Disconnects
If you're using the scp or ssh tasks with ant, you may run into a problem where part way during the upload or never disconnecting after the command completes for the ssh task. There are a couple of possible causes:
- The scp problem is almost certainly caused by using ant 1.7.0 or below and jsch 0.1.30 or above. You could upgrade to the latest nightly of ant1 but it's probably easier to just drop back to jsch 0.1.29 which is what ant was developed against and works nicely. Bug 41090 contains the gory details.
- If the command you're executing with the ssh task starts a background service or otherwise leaves a process running, that may be the cause of the problem. You can add 'shopt -s huponexit' to your /etc/profile, .bashrc or somewhere like that. I must admit, I'm somewhat vague on the exact details of what that does but the basic idea seems to be to signal any background processes that bash is exiting and then not wait for them to complete (which allows your ssh connection to close). If you're starting a server they'll probably ignore the hup signal it sends and if not, use the nohup command.
Hopefully that will be the last I'll see of that issue.
1 – which seems to mean compiling from source at the moment, since the nightly build directory the Ant website links to is empty↩

October 24th, 2007 at 5:48 am
We intermittently had a similar problem at work. Interactive ssh with X forwarding, though.
With ssh -vvv we tracked it to an xauth process being started and not exiting every time, and when PuTTY clients exited the xauth process would go to 100% CPU. I think we eventually tracked it down to something about people’s home areas being auto-mounted from a new Linux box, and xauth was looking to read or write some magic cookie and it got all upset.
November 20th, 2007 at 6:22 am
Thanks a million for this post. I was going crazy thinking it was my limited understanding of Ant. With Ant 1.7.0, jsch .1.29 works perfectly, as you mentioned. Btw, the direct link to this older release is here: http://sourceforge.net/project/downloading.php?group_id=64920&use_mirror=easynews&filename=jsch-0.1.29.jar&96256293
July 13th, 2008 at 4:32 am
[...] with an ant task Filed under: Java, News — Peter @ 6:35 pm After studying the workaround I can now deploy a file to my sourceforge directory. Now I don’t need to upload the file [...]
July 13th, 2008 at 9:04 am
Thank you so much for this post — reverting back to use jsch-0.1.29.jar worked! (instead of jsch-0.1.39.jar)
August 23rd, 2008 at 3:44 am
A workaround I found is to use sftp=”true” .
September 16th, 2008 at 2:51 am
I tried out the options. However, I could not get it working.
I used “timeout” and “failonerror” options to drop the connection
Example:
failonerror=”no”
timeout=”30000″