|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.tools.ant.ProjectComponent | +--org.apache.tools.ant.Task | +--org.apache.tools.ant.taskdefs.optional.net.FTP
Basic FTP client. Performs the following actions:
Nested Class Summary | |
static class |
FTP.Action
an action to perform, one of "send", "put", "recv", "get", "del", "delete", "list", "mkdir", "chmod", "rmdir" |
protected class |
FTP.FTPDirectoryScanner
internal class allowing to read the contents of a remote file system using the FTP protocol used in particular for ftp get operations differences with DirectoryScanner "" (the root of the fileset) is never included in the included directories followSymlinks defaults to false |
Field Summary | |
protected static java.lang.String[] |
ACTION_STRS
|
protected static java.lang.String[] |
ACTION_TARGET_STRS
|
protected static int |
CHMOD
|
protected static java.lang.String[] |
COMPLETED_ACTION_STRS
|
static int |
DEFAULT_FTP_PORT
Default port for FTP |
protected static int |
DEL_FILES
|
protected static int |
GET_FILES
|
protected static int |
LIST_FILES
|
protected static int |
MK_DIR
|
protected static int |
RM_DIR
|
protected static int |
SEND_FILES
|
Fields inherited from class org.apache.tools.ant.Task |
description, location, target, taskName, taskType, wrapper |
Fields inherited from class org.apache.tools.ant.ProjectComponent |
project |
Constructor Summary | |
FTP()
|
Method Summary | |
void |
addFileset(FileSet set)
A set of files to upload or download |
protected void |
checkConfiguration()
Checks to see that all required parameters are set. |
protected void |
createParents(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String filename)
Creates all parent directories specified in a complete relative pathname. |
protected void |
delFile(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String filename)
Delete a file from the remote host. |
protected void |
doSiteCommand(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String theCMD)
Sends a site command to the ftp server |
void |
execute()
Runs the task. |
protected void |
getFile(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String dir,
java.lang.String filename)
Retrieve a single file from the remote host. |
protected boolean |
isUpToDate(org.apache.commons.net.ftp.FTPClient ftp,
java.io.File localFile,
java.lang.String remoteFile)
Checks to see if the remote file is current as compared with the local file. |
protected void |
listFile(org.apache.commons.net.ftp.FTPClient ftp,
java.io.BufferedWriter bw,
java.lang.String filename)
List information about a single file from the remote host. |
protected void |
makeRemoteDir(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String dir)
Create the specified directory on the remote host. |
protected java.lang.String |
resolveFile(java.lang.String file)
Correct a file path to correspond to the remote host requirements. |
protected void |
rmDir(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String dirname)
Delete a directory, if empty, from the remote host. |
protected void |
sendFile(org.apache.commons.net.ftp.FTPClient ftp,
java.lang.String dir,
java.lang.String filename)
Sends a single file to the remote host. |
void |
setAction(FTP.Action action)
Sets the FTP action to be taken. |
void |
setAction(java.lang.String action)
Deprecated. 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. |
void |
setBinary(boolean binary)
If true, uses binary mode, otherwise text mode (default is binary). |
void |
setChmod(java.lang.String theMode)
Sets the file permission mode (Unix only) for files sent to the server. |
void |
setDepends(boolean depends)
Set to true to transmit only files that are new or changed from their remote counterparts. |
void |
setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors)
set the flag to skip errors on directory creation. |
void |
setListing(java.io.File listing)
The output file for the "list" action. |
void |
setNewer(boolean newer)
A synonym for depends. |
void |
setPassive(boolean passive)
Specifies whether to use passive mode. |
void |
setPassword(java.lang.String password)
Sets the login password for the given user id. |
void |
setPort(int port)
Sets the FTP port used by the remote server. |
void |
setPreserveLastModified(boolean preserveLastModified)
Set to true to preserve modification times for "gotten" files. |
void |
setRemotedir(java.lang.String dir)
Sets the remote directory where files will be placed. |
void |
setSeparator(java.lang.String separator)
Sets the remote file separator character. |
void |
setServer(java.lang.String server)
Sets the FTP server to send files to. |
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. |
void |
setTimeDiffAuto(boolean timeDiffAuto)
"true" to find out automatically the time difference between local and remote machine. |
void |
setTimeDiffMillis(long timeDiffMillis)
number of milliseconds to add to the time on the remote machine to get the time on the local machine. |
void |
setUmask(java.lang.String theUmask)
Sets the default mask for file creation on a unix server. |
void |
setUserid(java.lang.String userid)
Sets the login user id to use on the specified server. |
void |
setVerbose(boolean verbose)
Set to true to receive notification about each file as it is transferred. |
protected void |
transferFiles(org.apache.commons.net.ftp.FTPClient ftp)
Sends all files specified by the configured filesets to the remote server. |
protected int |
transferFiles(org.apache.commons.net.ftp.FTPClient ftp,
FileSet fs)
For each file in the fileset, do the appropriate action: send, get, delete, or list. |
Methods inherited from class org.apache.tools.ant.Task |
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType |
Methods inherited from class org.apache.tools.ant.ProjectComponent |
getProject, setProject |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int SEND_FILES
protected static final int GET_FILES
protected static final int DEL_FILES
protected static final int LIST_FILES
protected static final int MK_DIR
protected static final int CHMOD
protected static final int RM_DIR
public static final int DEFAULT_FTP_PORT
protected static final java.lang.String[] ACTION_STRS
protected static final java.lang.String[] COMPLETED_ACTION_STRS
protected static final java.lang.String[] ACTION_TARGET_STRS
Constructor Detail |
public FTP()
Method Detail |
public void setRemotedir(java.lang.String dir)
dir
- the remote directory name.public void setServer(java.lang.String server)
server
- the remote server name.public void setPort(int port)
port
- the port on which the remote server is listening.public void setUserid(java.lang.String userid)
userid
- remote system userid.public void setPassword(java.lang.String password)
password
- the password on the remote system.public void setBinary(boolean binary)
binary
- if true use binary mode in transfers.public void setPassive(boolean passive)
passive
- true is passive mode should be used.public void setVerbose(boolean verbose)
verbose
- true if verbose notifications are required.public void setNewer(boolean newer)
newer
- if true only transfer newer files.public void setTimeDiffMillis(long timeDiffMillis)
newer
timeDiffMillis
- number of millisecondspublic void setTimeDiffAuto(boolean timeDiffAuto)
timeDiffAuto
- true = find automatically the time diffpublic void setPreserveLastModified(boolean preserveLastModified)
preserveLastModified
- if true preserver modification times.public void setDepends(boolean depends)
depends
- if true only transfer newer files.public void setSeparator(java.lang.String separator)
separator
- the file separator on the remote system.public void setChmod(java.lang.String theMode)
theMode
- unix style file mode for the files sent to the remote
system.public void setUmask(java.lang.String theUmask)
theUmask
- unix style umask for files created on the remote server.public void addFileset(FileSet set)
set
- the set of files to be added to the list of files to be
transferred.public void setAction(java.lang.String action) throws BuildException
action
- the FTP action to be performed.
BuildException
- if the action is not a valid action.public void setAction(FTP.Action action) throws BuildException
action
- the FTP action to be performed.
BuildException
- if the action is not a valid action.public void setListing(java.io.File listing)
listing
- file in which to store the listing.public void setSkipFailedTransfers(boolean skipFailedTransfers)
skipFailedTransfers
- true if failures in transfers are ignored.public void setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors)
ignoreNoncriticalErrors
- true if non-critical errors should not
cause a failure.protected void checkConfiguration() throws BuildException
BuildException
- if the configuration is not valid.protected int transferFiles(org.apache.commons.net.ftp.FTPClient ftp, FileSet fs) throws java.io.IOException, BuildException
ftp
- the FTPClient instance used to perform FTP actionsfs
- the fileset on which the actions are performed.
java.io.IOException
- if there is a problem reading a file
BuildException
- if there is a problem in the configuration.protected void transferFiles(org.apache.commons.net.ftp.FTPClient ftp) throws java.io.IOException, BuildException
ftp
- the FTPClient instance used to perform FTP actions
java.io.IOException
- if there is a problem reading a file
BuildException
- if there is a problem in the configuration.protected java.lang.String resolveFile(java.lang.String file)
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
protected void createParents(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String filename) throws java.io.IOException, BuildException
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.
java.io.IOException
- under non documented circumstances
BuildException
- if it is impossible to cd to a remote directoryprotected boolean isUpToDate(org.apache.commons.net.ftp.FTPClient ftp, java.io.File localFile, java.lang.String remoteFile) throws java.io.IOException, BuildException
ftp
- ftpclientlocalFile
- local fileremoteFile
- remote file
java.io.IOException
- in unknown circumstances
BuildException
- if the date of the remote files cannot be found and the action is
GET_FILESprotected void doSiteCommand(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String theCMD) throws java.io.IOException, BuildException
ftp
- ftp clienttheCMD
- command to execute
java.io.IOException
- in unknown circumstances
BuildException
- in unknown circumstancesprotected void sendFile(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dir, java.lang.String filename) throws java.io.IOException, BuildException
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
java.io.IOException
- in unknown circumstances
BuildException
- in unknown circumstancesprotected void delFile(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String filename) throws java.io.IOException, BuildException
ftp
- ftp clientfilename
- file to delete
java.io.IOException
- in unknown circumstances
BuildException
- if skipFailedTransfers is set to false
and the deletion could not be doneprotected void rmDir(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dirname) throws java.io.IOException, BuildException
ftp
- ftp clientdirname
- directory to delete
java.io.IOException
- in unknown circumstances
BuildException
- if skipFailedTransfers is set to false
and the deletion could not be doneprotected void getFile(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dir, java.lang.String filename) throws java.io.IOException, BuildException
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)
java.io.IOException
- in unknown circumstances
BuildException
- if skipFailedTransfers is false
and the file cannot be retrieved.protected void listFile(org.apache.commons.net.ftp.FTPClient ftp, java.io.BufferedWriter bw, java.lang.String filename) throws java.io.IOException, BuildException
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
java.io.IOException
- in unknown circumstances
BuildException
- in unknown circumstancesprotected void makeRemoteDir(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dir) throws java.io.IOException, BuildException
ftp
- The FTP client connectiondir
- The directory to create (format must be correct for host
type)
java.io.IOException
- in unknown circumstances
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 BuildExceptionpublic void execute() throws BuildException
execute
in class Task
BuildException
- if the task fails or is not configured
correctly.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |