How To Run Ant FTP / Telnet / Rexec Task
Ant (java software) from Apache Foundation is a popular build tool (often used successfully with other release management tasks) which replaces make.
"Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's wrinkles. "
Included in Ant are optional tasks like FTP & Telnet. For example the FTP Task allows you to communicate with FTP servers (get / put / list etc.).
Unfortunately they don't work out of box and not well documented. In this article we will explain the whole procedure in six simple steps.
To use them follow the steps below:
- Download jakarta-oro and commons-net library.
Note: The links above allow you to download the version I tested them with. - Create a lib directory for your project if you have not already done so.
- Extract the jar file jakarta-oro*.jar from jakarta-oro library you have downloaded and copy it to the lib directory you created.
Note:- If you have downloaded from the links in step 1 then the exact file name is jakarta-oro-2.0.8.jar
- Ensure that the file is copied to the lib directory and not to any of its sub-directories
- Extract the jar file commons-net*.jar file from commons-net library you have downloaded and copy it to the lib directory.
Note:- If you have downloaded from the links in step 1 then the exact file name is commons-net-1.4.0.jar
- Ensure that the file is copied to the lib directory and not to any of its sub-directories
- Add the ftp taskdef at the top:
- Add the appropriate task to your build.xml file. An example task to upload a directory is as follows:

- Run Ant by including the lib directory in classpath. An example would be:
ant -lib lib upload
Note: I just had to include the lib directory to ensure all its jar files are automatically included.
Note:
- The same procedure can be used to run Ant Telnet and RExec Tasks. Only the task name and parameters in build.xml file will change. Check the corresponding manuals for details.
- I have promoted the use of lib directory (within project) to keep your jar files. This makes your jar files available only to your project. There are two other alternatives. First you can keep them in %ANT_HOME%\lib directory. This makes them available to all projects for all users in that machine.
You can also keep them in ${user.home}/.ant/lib.The location of ${user.home}/.ant/lib is somewhat dependent on the JVM. On Unix systems ${user.home} maps to the user's home directory whilst on recent versions of Windows it will be somewhere such as C:\Documents and Settings\username\.ant\lib.
Enjoy!
Filed under Headline News, How To, Java Software, Tech Note | Tags: Extract, Jakarta |
14 Comments |
Email this Article


April 6th, 2006 at 6:41 am
Dear Sir,
I followed the six steps, but the example didn’t work. When I execute “ant -lib lib upload” the following message is printed:
C:\Temp\testeRemoto\build.xml:25: Could not create task or type of type: http://ftp.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
- You have misspelt ‘ftp’.
Fix: check your spelling.
- The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the ‘ant-’ JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
- The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
- The task is not an Ant core or optional task
and needs to be declared using .
- You are attempting to use a task defined using
or but have spelt wrong or not
defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath
Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.
Total time: 0 seconds
Thank you.
Cordially,
Marcelo.
April 6th, 2006 at 9:24 am
You need to add the taskdef for http://ftp. See the article (updated) for details.
August 26th, 2006 at 6:40 am
Hi
I followed the steps outlined in the article and
copied the jars to my %ANT_HOME%\lib directory.
I also added the jars in classpath.
Still when I run my ftp task I get the following message:
taskdef class org.apache.tools.ant.taskdefs.optional.net.FTP cannot be found
Thanks,
Nikesh
August 26th, 2006 at 9:09 am
Please install the ant optional jars, specifically the one for http://ftp.
September 28th, 2006 at 9:42 am
i followed the steps and got this error
Error reading project file C:\apache-ant-1.6.5\build_ftp.xml: Invalid byte 1 of 1-byte UTF-8 sequence
September 29th, 2006 at 3:27 pm
i deleted all th ant dirs, cleared the classpaths and downloaded afresh copy of bin dist.
everything works great even with out classpaths.
hope this helps someone else
December 13th, 2006 at 7:21 am
i face this error..
BUILD FAILED: java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
my target i supplied in build.xml file is :
can u plz helpe out to resolve this problem.
December 13th, 2006 at 7:25 am
continued…
—————————————-
July 13th, 2007 at 1:36 am
Hi,
I want to use telnet task for connecting to a unix server and start build there. I tried and its working. But the problem is, after i give a build command in telnet, its immediately comming out. If i add a tag to wait for some string, then it works. Now the issue is i cannot have the same read tag for a fixed string always. If my build fails in then the string can be different. How can we solve this?
August 2nd, 2007 at 4:55 pm
BUILD FAILED: java.lang.NoClassDefFoundError: I got this error too :-org/apache/commons/net/ftp/FTPClient
When I built it after adding to the classpath from cmd prompt, it is giving me the following error:
C:\ATG\ATG2006.3\NutriSystem\build.xml:210: error during FTP transfer: java.net.
SocketException: Connection reset
November 12th, 2008 at 3:09 am
Bonjour,
je suis d’ordinaire assez respectueux du travail qui fournit gratuitement par la communauté informatique.
Cependant, dans celui ci la qualité du français utilisé est franchement déplorable…
Je vous recommande de vous faire aider par quelqu’un dont le français est sa langue maternelle.
Cordialement
March 11th, 2009 at 7:49 pm
Pour du français, c’est déplorable, j’en conviens. Mais pour de l’anglais, c’est passable!
To the owner of this web site: The XML doesn’t show. Did you copy and paste the information form somewhere? If I google a few phrases of this page, I can find the original page, with nothing lost in the copy. What a waste of bandwidth!
March 11th, 2009 at 8:22 pm
Florian,
The code you get here is original. Unfortunately WordPress doesn’t like codes and messes with them seriously.
Anyway now you can see the code properly as I am using images.
July 30th, 2009 at 1:28 pm
If you’re using Fedora 11, make sure to install the ant-commons-net package using “yum install ant-commons-net” otherwise builds fail with an
org.apache.tools.ant.taskdefs.optional.net.FTP error.
Regards