Basic FTP client. Performs the following actions:
- send - send files to a remote server. This is the
default action.
- get - retrieve files from a remote server.
- del - delete files from a remote server.
- list - create a file listing.
- chmod - change unix file permissions.
- rmdir - remove directories, if empty, from a
remote server.
Note: Some FTP servers - notably the Solaris server - seem
to hold data ports open after a "retr" operation, allowing them to timeout
instead of shutting them down cleanly. This happens in active or passive
mode, and the ports will remain open even after ending the FTP session. FTP
"send" operations seem to close ports immediately. This behavior may cause
problems on some systems when downloading large sets of files.
ACTION_STRS
protected static final String[] ACTION_STRS
ACTION_TARGET_STRS
protected static final String[] ACTION_TARGET_STRS
CHMOD
protected static final int CHMOD
COMPLETED_ACTION_STRS
protected static final String[] COMPLETED_ACTION_STRS
DEFAULT_FTP_PORT
public static final int DEFAULT_FTP_PORT
Default port for FTP
DEL_FILES
protected static final int DEL_FILES
GET_FILES
protected static final int GET_FILES
LIST_FILES
protected static final int LIST_FILES
MK_DIR
protected static final int MK_DIR
RM_DIR
protected static final int RM_DIR
SEND_FILES
protected static final int SEND_FILES
addFileset
public void addFileset(FileSet set)
A set of files to upload or download
set
- the set of files to be added to the list of files to be
transferred.
checkConfiguration
protected void checkConfiguration()
throws BuildException
Checks to see that all required parameters are set.
createParents
protected void createParents(FTPClient ftp,
String filename)
throws IOException,
BuildException
Creates all parent directories specified in a complete relative
pathname. Attempts to create existing directories will not cause
errors.
ftp
- the FTP client instance to use to execute FTP actions on
the remote server.filename
- the name of the file whose parents should be created.
delFile
protected void delFile(FTPClient ftp,
String filename)
throws IOException,
BuildException
Delete a file from the remote host.
ftp
- ftp clientfilename
- file to delete
BuildException
- if skipFailedTransfers is set to false
and the deletion could not be done
doSiteCommand
protected void doSiteCommand(FTPClient ftp,
String theCMD)
throws IOException,
BuildException
Sends a site command to the ftp server
ftp
- ftp clienttheCMD
- command to execute
getFile
protected void getFile(FTPClient ftp,
String dir,
String filename)
throws IOException,
BuildException
Retrieve a single file from the remote host.
filename
may
contain a relative path specification.
The file will then be retreived using the entire relative path spec -
no attempt is made to change directories. It is anticipated that this
may eventually cause problems with some FTP servers, but it simplifies
the coding.
ftp
- the ftp clientdir
- local base directory to which the file should go backfilename
- relative path of the file based upon the ftp remote directory
and/or the local base directory (dir)
BuildException
- if skipFailedTransfers is false
and the file cannot be retrieved.
isUpToDate
protected boolean isUpToDate(FTPClient ftp,
File localFile,
String remoteFile)
throws IOException,
BuildException
Checks to see if the remote file is current as compared with the local
file. Returns true if the target file is up to date.
ftp
- ftpclientlocalFile
- local fileremoteFile
- remote file
- true if the target file is up to date
BuildException
- if the date of the remote files cannot be found and the action is
GET_FILES
listFile
protected void listFile(FTPClient ftp,
BufferedWriter bw,
String filename)
throws IOException,
BuildException
List information about a single file from the remote host.
filename
may contain a relative path specification.
The file listing will then be retrieved using the entire relative path
spec - no attempt is made to change directories. It is anticipated that
this may eventually cause problems with some FTP servers, but it
simplifies the coding.
ftp
- ftp clientbw
- buffered writerfilename
- the directory one wants to list
makeRemoteDir
protected void makeRemoteDir(FTPClient ftp,
String dir)
throws IOException,
BuildException
Create the specified directory on the remote host.
ftp
- The FTP client connectiondir
- The directory to create (format must be correct for host
type)
BuildException
- if ignoreNoncriticalErrors has not been set to true
and a directory could not be created, for instance because it was
already existing. Precisely, the codes 521, 550 and 553 will trigger
a BuildException
resolveFile
protected String resolveFile(String file)
Correct a file path to correspond to the remote host requirements. This
implementation currently assumes that the remote end can handle
Unix-style paths with forward-slash separators. This can be overridden
with the separator
task parameter. No attempt is made to
determine what syntax is appropriate for the remote host.
file
- the remote file name to be resolved
- the filename as it will appear on the server.
rmDir
protected void rmDir(FTPClient ftp,
String dirname)
throws IOException,
BuildException
Delete a directory, if empty, from the remote host.
ftp
- ftp clientdirname
- directory to delete
BuildException
- if skipFailedTransfers is set to false
and the deletion could not be done
sendFile
protected void sendFile(FTPClient ftp,
String dir,
String filename)
throws IOException,
BuildException
Sends a single file to the remote host. filename
may
contain a relative path specification. When this is the case, sendFile
will attempt to create any necessary parent directories before sending
the file. The file will then be sent using the entire relative path
spec - no attempt is made to change directories. It is anticipated that
this may eventually cause problems with some FTP servers, but it
simplifies the coding.
ftp
- ftp clientdir
- base directory of the file to be sent (local)filename
- relative path of the file to be send
locally relative to dir
remotely relative to the remotedir attribute
setAction
public void setAction(String action)
throws BuildException
setAction(String) is deprecated and is replaced with
setAction(FTP.Action) to make Ant's Introspection mechanism do the
work and also to encapsulate operations on the type in its own
class.
Sets the FTP action to be taken. Currently accepts "put", "get", "del",
"mkdir" and "list".
action
- the FTP action to be performed.
setAction
public void setAction(FTP.Action action)
throws BuildException
Sets the FTP action to be taken. Currently accepts "put", "get", "del",
"mkdir", "chmod" and "list".
action
- the FTP action to be performed.
setBinary
public void setBinary(boolean binary)
If true, uses binary mode, otherwise text mode (default is binary).
binary
- if true use binary mode in transfers.
setChmod
public void setChmod(String theMode)
Sets the file permission mode (Unix only) for files sent to the
server.
theMode
- unix style file mode for the files sent to the remote
system.
setDepends
public void setDepends(boolean depends)
Set to true to transmit only files that are new or changed from their
remote counterparts. The default is to transmit all files.
depends
- if true only transfer newer files.
setIgnoreNoncriticalErrors
public void setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors)
set the flag to skip errors on directory creation.
(and maybe later other server specific errors)
ignoreNoncriticalErrors
- true if non-critical errors should not
cause a failure.
setListing
public void setListing(File listing)
The output file for the "list" action. This attribute is ignored for
any other actions.
listing
- file in which to store the listing.
setNewer
public void setNewer(boolean newer)
A synonym for depends. Set to true to transmit only new
or changed files.
See the related attributes timediffmillis and timediffauto.
newer
- if true only transfer newer files.
setPassive
public void setPassive(boolean passive)
Specifies whether to use passive mode. Set to true if you are behind a
firewall and cannot connect without it. Passive mode is disabled by
default.
passive
- true is passive mode should be used.
setPassword
public void setPassword(String password)
Sets the login password for the given user id.
password
- the password on the remote system.
setPort
public void setPort(int port)
Sets the FTP port used by the remote server.
port
- the port on which the remote server is listening.
setPreserveLastModified
public void setPreserveLastModified(boolean preserveLastModified)
Set to true to preserve modification times for "gotten" files.
preserveLastModified
- if true preserver modification times.
setRemotedir
public void setRemotedir(String dir)
Sets the remote directory where files will be placed. This may be a
relative or absolute path, and must be in the path syntax expected by
the remote server. No correction of path syntax will be performed.
dir
- the remote directory name.
setSeparator
public void setSeparator(String separator)
Sets the remote file separator character. This normally defaults to the
Unix standard forward slash, but can be manually overridden using this
call if the remote server requires some other separator. Only the first
character of the string is used.
separator
- the file separator on the remote system.
setServer
public void setServer(String server)
Sets the FTP server to send files to.
server
- the remote server name.
setSkipFailedTransfers
public void setSkipFailedTransfers(boolean skipFailedTransfers)
If true, enables unsuccessful file put, delete and get
operations to be skipped with a warning and the remainder
of the files still transferred.
skipFailedTransfers
- true if failures in transfers are ignored.
setTimeDiffAuto
public void setTimeDiffAuto(boolean timeDiffAuto)
"true" to find out automatically the time difference
between local and remote machine.
This requires right to create
and delete a temporary file in the remote directory.
timeDiffAuto
- true = find automatically the time diff
setTimeDiffMillis
public void setTimeDiffMillis(long timeDiffMillis)
number of milliseconds to add to the time on the remote machine
to get the time on the local machine.
use in conjunction with newer
timeDiffMillis
- number of milliseconds
setUmask
public void setUmask(String theUmask)
Sets the default mask for file creation on a unix server.
theUmask
- unix style umask for files created on the remote server.
setUserid
public void setUserid(String userid)
Sets the login user id to use on the specified server.
userid
- remote system userid.
setVerbose
public void setVerbose(boolean verbose)
Set to true to receive notification about each file as it is
transferred.
verbose
- true if verbose notifications are required.
transferFiles
protected void transferFiles(FTPClient ftp)
throws IOException,
BuildException
Sends all files specified by the configured filesets to the remote
server.
ftp
- the FTPClient instance used to perform FTP actions
transferFiles
protected int transferFiles(FTPClient ftp,
FileSet fs)
throws IOException,
BuildException
For each file in the fileset, do the appropriate action: send, get,
delete, or list.
ftp
- the FTPClient instance used to perform FTP actionsfs
- the fileset on which the actions are performed.
- the number of files to be transferred.