# Ant User Manual

## FTP

### Description

Note: The ftp-task uses the NetComponents-Package which you will need to download from http://www.savarese.org and add to your classpath.

The ftp task implements a basic FTP client that can send, receive, list, and delete files. See below for descriptions and examples of how to perform each task.

The ftp task makes no attempt to determine what file system syntax is required by the remote server, and defaults to Unix standards. remotedir must be specified in the exact syntax required by the ftp server. If the usual Unix conventions are not supported by the server, separator can be used to set the file separator that should be used instead.

See the section on directory based tasks, on how the inclusion/exclusion of files works, and how to write patterns.

### Parameters

Attribute | Description | Required
server | the address of the remote ftp server. | Yes
port | the port number of the remote ftp server. Defaults to port 21. | No
userid | the login id to use on the ftp server. | Yes
password | the login password to use on the ftp server. | Yes
remotedir | the directory to which to upload files on the ftp server. | No
action | the ftp action to perform, defaulting to "send". Currently supports "put", "get", "del", and "list". | No
binary | selects binary-mode ("yes") or text-mode ("no") transfers. Defaults to "yes" | No
passive | selects passive-mode ("yes") transfers. Defaults to "no" | No
verbose | displays information on each file transferred if set to "yes". Defaults to "no". | No
depends | transfers only new or changed files if set to "yes". Defaults to "no". | No
newer | a synonym for depends. | No
separator | sets the file separator used on the ftp server. Defaults to "/". | No
listing | the file to write results of the "list" action. Required for the "list" action, ignored otherwise. | No

### Sending Files

The easiest way to describe how to send files is with a couple of examples:

      <ftp server="ftp.apache.org"
           userid="anonymous"
           password="me@myorg.com">
        <fileset dir="htdocs/manual"/>
      </ftp>

Logs in to `ftp.apache.org` as `anonymous` and uploads all files in the `htdocs/manual` directory to the default directory for that user.

      <ftp server="ftp.apache.org"
           remotedir="incoming"
           userid="anonymous"
           password="me@myorg.com"
           depends="yes"
      >
        <fileset dir="htdocs/manual"/>
      </ftp>

Logs in to `ftp.apache.org` as `anonymous` and uploads all new or changed files in the `htdocs/manual` directory to the `incoming` directory relative to the default directory for `anonymous`.

      <ftp server="ftp.apache.org"
           port="2121"
           remotedir="/pub/incoming"
           userid="coder"
           password="java1"
           depends="yes"
           binary="no"
      >
        <fileset dir="htdocs/manual">
          <include name="**/*.html"/>
        </fileset>
      </ftp>

Logs in to `ftp.apache.org` at port `2121` as `coder` with password `java1` and uploads all new or changed HTML files in the `htdocs/manual` directory to the `/pub/incoming` directory. The files are transferred in text mode. Passive mode has been switched on to send files from behind a firewall.

      <ftp server="ftp.nt.org"
           remotedir="c:\uploads"
           userid="coder"
           password="java1"
           separator="\"
           verbose="yes"

      >
        <fileset dir="htdocs/manual">
          <include name="**/*.html"/>
        </fileset>
      </ftp>

Logs in to the Windows-based `ftp.nt.org` as `coder` with password `java1` and uploads all HTML files in the `htdocs/manual` directory to the `c:\uploads` directory. Progress messages are displayed as each file is uploaded.

### Getting Files

Getting files from an FTP server works pretty much the same way as sending them does. The only difference is that the nested filesets use the remotedir attribute as the base directory for the files on the FTP server, and the dir attribute as the local directory to put the files into. The file structure from the FTP site is preserved on the local machine.

      <ftp action="get"
           server="ftp.apache.org"
           userid="anonymous"
           password="me@myorg.com">
        <fileset dir="htdocs/manual" >
          <include name="**/*.html"/>
        </fileset>
      </ftp>

Logs in to `ftp.apache.org` as `anonymous` and recursively downloads all .html files from default directory for that user into the `htdocs/manual` directory on the local machine.

### Deleting Files

As you've probably guessed by now, you use nested fileset elements to select the files to delete from the remote FTP server. Again, the filesets are relative to the remote directory, not a local directory. In fact, the dir attribute of the fileset is ignored completely.

      <ftp action="del"
           server="ftp.apache.org"
           userid="anonymous"
           password="me@myorg.com" >
        <fileset>
          <include name="**/*.tmp"/>
        </fileset>
      </ftp>

Logs in to `ftp.apache.org` as `anonymous` and tries to delete all *.tmp files from the default directory for that user. If you don't have permission to delete a file, a BuildException is thrown.

### Listing Files

      <ftp action="list"
           server="ftp.apache.org"
           userid=quot;anonymous"
           password="me@myorg.com"
           listing="data/ftp.listing" >
        <fileset>
          <include name="**"/>
        </fileset>
      </ftp>

This provides a file listing in `data/ftp.listing` of all the files on the FTP server relative to the default directory of the `anonymous` user. The listing is in whatever format the FTP server normally lists files.

Copyright © 2000,2001 Apache Software Foundation. All rights Reserved.