Friday, May 30, 2008

0 How To Run Ant FTP / Telnet / Rexec Task

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:

  1. Download jakarta-oro and commons-net library.
    Note: The links above allow you to download the version I tested them with.
  2. Create a lib directory for your project if you have not already done so.
  3. 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
  4. 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
  5. Add the ftp taskdef at the top:
  6. Add the appropriate task to your build.xml file. An example task to upload a directory is as follows:
       description="Upload the files to WordPress Installation" >
    remotedir="/test" server="taragana.com"
    userid="ftp_login" password="ftp_password">



  7. 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.