ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [PATCH] Added get. list, and del functionality to FTP task
Date Fri, 18 Aug 2000 17:14:46 GMT

The patch and new file are attachements to this email, as I've had problems
with Lotus Notes gateways messing up the line breaks.

This patch adds get, list, and delete functionality to the optional FTP
task.  If the patch gets committed, I'll update index.html at that time.

I had my own task using the same NetComponents.jar library, but it was
written a while ago, only did send, and it isn't as clean as Roger's.  We
have a new build project where we suddenly have the need for an FTP client,
so I figured I might as well make the changes to the existing task.

There are a couple of implications to adding the capability to get files
from an FTP server and using the standard FileSet.  The problem is that the
directory scanner the fileset returns assumes that the files are on the
local drive.  As an example, say our current directory is
/home/tstproject/src, we are connecting to some FTP server, and we don't
have to change directory on the FTP server (so we are in /home/ftp/pub).
So saying something like

<ftp action="get" ...>
  <fileset dir=".">
    <include name="**/*.xml" />

you would assume that all the .xml files in /home/ftp/pub and down would be
put in /home/tstproject/src, preserving directory structure.  This doesn't
happen with the current implementation of DirectoryScanner.  We need a
custom directory scanner that understands how to get information from the
FTP server.

In comes the interface IDirectoryScanner, making DirectoryScanner implement
IDirectoryScanner and promoting its private fields and methods to
protected, and creating an inner class FTP.FTPDirectoryScanner that extends
DirectoryScanner.  The final step is to create a public method
setupDirectoryScanner in FileSet that accepts an IDirectoryScanner and
Project.  The upshot of all this is that all tasks that make use of
DirectoryScanner and FileSet work unchanged, I get a custom directory
scanner that makes use of the FTP code from ORO, and things work the way we

Sending Files
  Works exactly the same as it does now.

Getting Files

  <ftp action="get"
    <fileset dir="xml_files_from_${ftp_server">
      <include name="**/*.xml" />

This will get all XML files from ftp_server (say, putting
them in the subdirectory, preserving the
directory structure from the FTP server.

Deleting Files

  <ftp action="delete"
      <include name="**/*.tmp" />

This task would delete all the .tmp files from the FTP server.

This action is understandably more dangerous.  However, it is obviously
limited by what permissions the user id has on the FTP server.  If you
can't delete the file, a BuildException is thrown.  The assumption here is
that if you are trying to delete files, you should know if you are allowed
to delete them or not. :-)  In addition, the dir attribute of the fileset
is ignored.  Its assumed that the root directory is the directory you've
changed to on the FTP server.  The reason it's ignored is that dir is
resolved to a local file name whether you want it do be or not, because dir
is a File, and the IntrospectionHelper automatically assumes that the File
is local to the system. (And that is perfectly reasonable behaviour - no
objections on my part.)

Listing Files

  <ftp action="list"
      <includes name="**" />

This provides a file listing in ${ftp_server}.listing of all the files on
the FTP server.  The listing is in whatever format the FTP server normally
lists files.

With this action, the "listing" attribute is required, and the dir
attribute of fileset is ignored.  Same reasoning as above.

Glenn McAllister
TID - Software Developer - VisualAge for Java
IBM Toronto Lab, (416) 448-3805
"An approximate answer to the right question is better than the
right answer to the wrong question." - John W. Tukey
(See attached file: ftp.patch)
(See attached file:

View raw message