How To Run Ant FTP / Telnet / Rexec Task
By Angsuman Chakraborty, Gaea News NetworkWednesday, November 2, 2005
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:
<taskdef name=”ftp” classname=”org.apache.tools.ant.taskdefs.optional.net.FTP”/> - 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!
July 30, 2009: 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 Regards |
March 11, 2009: 8:22 pm
Florian, |
Florian |
March 11, 2009: 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! |
FAYE |
November 12, 2008: 3:09 am
Bonjour, je suis d’ordinaire assez respectueux du travail qui fournit gratuitement par la communauté informatique. Cordialement |
Rohitash |
August 2, 2007: 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. |
Gandhi |
July 13, 2007: 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? |
devesh gupta |
devesh gupta |
December 13, 2006: 7:21 am
i face this error.. my target i supplied in build.xml file is : can u plz helpe out to resolve this problem. |
Sunny |
September 29, 2006: 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 |
Sunny |
September 28, 2006: 9:42 am
i followed the steps and got this error |
August 26, 2006: 9:09 am
Please install the ant optional jars, specifically the one for https://ftp. |
Nikesh |
August 26, 2006: 6:40 am
Hi I followed the steps outlined in the article and 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, |
April 6, 2006: 9:24 am
You need to add the taskdef for https://ftp. See the article (updated) for details. |
Marcelo Daride Gaspar |
April 6, 2006: 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: https://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 Remember that for JAR files to be visible to Ant tasks implemented Please neither file bug reports on this problem, nor email the Total time: 0 seconds Thank you. Cordially, Marcelo. |
Tony