«« Baby Steps May CD Run Review »»
blog header image
Using Ant's FTP Task

I'm going to be doing AudioMan's builds on one machine and uploading them to a web server with FTP so people can download them. The easiest way to do this was with Ant, the tool I use to build AudioMan. After building the project Ant already knows all of the details of the build it just did -- where it is, what all of the files are, etc.

One small problem though: <ftp> is an optional Ant task and requires an external library. What the documentation doesn't tell you is that Ant 1.6 requires a different external library file from Ant 1.5. That's what happens when you read the docs for 1.6 using 1.5, right? :) It would still be nice to know it changed. I Googled for it, and found the info telling me that it changed.

So that's handy, I was using the wrong JAR file. Just for the record:

Ant 1.5 requires NetComponents.jar which you can get here.
Ant 1.6 requires commons-net.jar which you can get here. It also requires the Jakarta ORO JAR file, which you can get here.


Here's a tip for the ftp task: If your Ant file is in a publicly accessible place like an open source CVS repository, you probably shouldn't put your password right in the Ant task like:

<ftp server="someftpserver.com" userid="user" password="god">
   <fileset file="somefile.zip" />

because people will know your FTP password! You're better off using a property, which you can leave blank in the Ant build.xml file and specify at the command line instead. Then the checked in file won't have a password in it and only the people that know the password can use this task. Here's the new Ant file:

<property name="ftp.password" value="" />

<ftp server="someftpserver.com" userid="user" password="${ftp.password}">
   <fileset file="somefile.zip" />

and here's how to use the command line to specify the password and run the ftp task:

ant -Dftp.password=god ftp

Posted at May 23, 2004 at 02:41 AM EST
Last updated May 23, 2004 at 02:41 AM EST

Thanx for posting the info.It helped me solve the problems rightaway.


» Posted by: Deepak at May 25, 2004 10:29 AM


Thanks for this posting. it was great and solved my problem right away tooooooo....

Hooray for the net.

» Posted by: Lakshman at June 16, 2004 12:41 AM

Good work:)

Thanks... it help me too :)

» Posted by: Swistak at June 18, 2004 07:09 AM

Yep, worked for me too. Thanks.

» Posted by: Shance at September 21, 2004 10:01 PM

Thanks for this information.
It solved my problem too.

» Posted by: Demoune at October 8, 2004 07:33 AM

Do you know of any way to use the Ant FTP task to send an arbitrary command to the ftp server?
I have a situation where to send large files to our mass storage server, I need to send a command verbatum.
at an FTP prompt, I type :
quote setcos 3
(this sets the size of file the hpss server will take, and how it deals with it..)

» Posted by: thomas at October 13, 2004 05:04 PM

thomas: It looks like this is not possible with the current version of Ant (1.6.2). There is a list of allowed "actions" that you can use instead of letting people use arbitrary commands.

» Posted by: Ryan at October 13, 2004 05:09 PM

I found this information extremely useful. I have one question though: how do you mention the remote ftp directory in which you want the files placed in the ftp task?
Would appreciate if you can respond as soon as possible.

Thanks and Regards,

» Posted by: Yamini at October 27, 2004 04:28 AM

Yamini, check out the FTP task in the Ant manual

It looks like it's the "remoteDir" attribute.


» Posted by: Ryan at October 27, 2004 08:34 AM


this works great, I however have a problem to use the "newer" option with downloads from different (eastward) timezones. It downloads the same file again if they are younger than the timezone difference. How do you handle this cases?

» Posted by: chris at November 17, 2004 03:37 PM

Thanks for the post of not only what the newer Ant required for FTP but also the links. Once I found your blog I literally had it up and running in 1 minute. Thanks!

» Posted by: J.R. at December 1, 2004 01:23 PM


This is great posting. With this change in file I was sweating over and could not find any solution. I am sure this will solve my problem. Thanks for sharing.


» Posted by: Pranav at April 27, 2005 09:45 AM
Search scope: Web ryanlowe.ca