Using FTP with ANT and FDT

by Sidney de Koning

Using FTP with ANT is a bit of a pickel… The Error messages you get are not very descriptive and the documentation is not that good in my opinion. However with further ado, here is my little quest with ANT and FTP.

The ANT FTP task connects to a remote server via the FTP protocol and provides all the basic FTP operations: send files, get files, delete files, create directories, delete directories, and can change file permissions using CHMOD.

To make sure ANT and FTP work we need to download a couple of JAR files to make it work. The ANT docs talk about:

FTP, rexec and telnet tasks:
jakarta-oro 2.0.8 or later is required together with commons-net 1.4.0.
For all users, a minimum version of commons-net of 1.4.0 is recommended. Earlier versions did not support the full range of configuration options, and 1.4.0 is needed to compile Ant.

The latest version of ‘jakarta-commons-net’ you can grab from here. And the latest version of ‘jakarta-oro’ can be found here (I used version 2.0.8 of Jakarta ORO and version 2.0 of the commons).

On a description of how to install JAR files to ANT’s class path please read this post. The process is exactly the same :) Then come back to this article.

Now we have set all of this up, dont forget to restart FDT and get ready to write some code!

The FTP task consists of a few basic elements and a lot optional properties. All the optional props can be found here.

A basic FTP session looks like this:


  
      
  

As you can see the FTP task has a fileset or file task embedded, this allows you to specify files or directories with files to be copied over to your ftp server.

What we will be doing is addding some extra properties because we want to have a little more control. I also added Growl support for ANT (i use it everywhere now, i love it :) )
We are going to add:

  1. binary – This selects binary-mode (‘yes’) or text-mode (‘no’) transfers. Defaults is ‘yes’
  2. passive – This selects passive-mode (‘yes’) transfers, for better through-firewall connectivity, at the price of performance. Defaults to ‘no’
  3. verbose – This displays information on each file transferred if set to ‘yes’. Defaults to ‘no’.
  4. depends – This transfers only new or changed files if set to ‘yes’. Defaults to ‘no’.

I took the example we created earlier and build on that. Added some extra tasks and also added more properties to the properties file.
As you can see from the properties file, i do everything with ‘variables’ this makes it more generic and usable for more projects.

The only thing with this ANT file is that you must use the same structure in directories i describe in the properties file. And you must have an folder that hold your Actionscript class files. They will be zipped and the uploaded to your FTP. How cool is that! And it saves you a bunch of time!

So here is the ANT build file and the properties file (right click -> save as) used in this example.
Dont forget to adjust the properties files to your needs, because else it does not work!
You run this example by calling the “Do Complete Deploy to FTP server” target from within the ANT build.

Enjoy!