org.apache.tools.ant.taskdefs.optional.net

Class FTPTask

public class FTPTask extends Task implements FTPTaskConfig

Basic FTP client. Performs the following actions: 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.

Since: Ant 1.3

Nested Class Summary
static classFTPTask.Action
an action to perform, one of "send", "put", "recv", "get", "del", "delete", "list", "mkdir", "chmod", "rmdir"
static classFTPTask.FTPSystemType
one of the valid system type keys recognized by the systemTypeKey attribute.
static classFTPTask.Granularity
represents one of the valid timestamp adjustment values recognized by the timestampGranularity attribute.

A timestamp adjustment may be used in file transfers for checking uptodateness.

Field Summary
static String[]ACTION_STRS
static String[]ACTION_TARGET_STRS
static intCHMOD
static String[]COMPLETED_ACTION_STRS
static intDEFAULT_FTP_PORT
Default port for FTP
static intDEL_FILES
static intGET_FILES
static intLIST_FILES
static intMK_DIR
static intRM_DIR
static intSEND_FILES
static intSITE_CMD
Method Summary
voidaddFileset(FileSet set)
A set of files to upload or download
protected voidcheckAttributes()
Checks to see that all required parameters are set.
PathcreateClasspath()
voidexecute()
Runs the task.
StringgetAccount()
intgetAction()
StringgetChmod()
StringgetDefaultDateFormatConfig()
booleangetEnableRemoteVerification()
VectorgetFilesets()
longgetGranularityMillis()
StringgetInitialSiteCommand()
FilegetListing()
StringgetPassword()
intgetPort()
StringgetRecentDateFormatConfig()
StringgetRemotedir()
intgetRetriesAllowed()
StringgetSeparator()
StringgetServer()
StringgetServerLanguageCodeConfig()
StringgetServerTimeZoneConfig()
StringgetShortMonthNamesConfig()
StringgetSiteCommand()
StringgetSystemTypeKey()
longgetTimeDiffMillis()
FTPTask.GranularitygetTimestampGranularity()
StringgetUmask()
StringgetUserid()
booleanisBinary()
booleanisConfigurationSet()
booleanisIgnoreNoncriticalErrors()
booleanisNewer()
booleanisPassive()
booleanisPreserveLastModified()
booleanisSkipFailedTransfers()
booleanisTimeDiffAuto()
booleanisVerbose()
voidsetAccount(String pAccount)
Sets the login account to use on the specified server.
voidsetAction(String action)
Sets the FTP action to be taken.
voidsetAction(FTPTask.Action action)
Sets the FTP action to be taken.
voidsetBinary(boolean binary)
If true, uses binary mode, otherwise text mode (default is binary).
voidsetChmod(String theMode)
Sets the file permission mode (Unix only) for files sent to the server.
voidsetDefaultDateFormatConfig(String defaultDateFormat)
Sets the defaultDateFormatConfig attribute.
voidsetDepends(boolean depends)
Set to true to transmit only files that are new or changed from their remote counterparts.
voidsetEnableRemoteVerification(boolean b)
Whether to verify that data and control connections are connected to the same remote host.
voidsetGranularityMillis(long granularity)
voidsetIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors)
set the flag to skip errors on directory creation. (and maybe later other server specific errors)
voidsetInitialSiteCommand(String initialCommand)
Sets the initialSiteCommand attribute.
voidsetListing(File listing)
The output file for the "list" action.
voidsetNewer(boolean newer)
A synonym for depends.
voidsetPassive(boolean passive)
Specifies whether to use passive mode.
voidsetPassword(String password)
Sets the login password for the given user id.
voidsetPort(int port)
Sets the FTP port used by the remote server.
voidsetPreserveLastModified(boolean preserveLastModified)
Set to true to preserve modification times for "gotten" files.
voidsetRecentDateFormatConfig(String recentDateFormat)
Sets the recentDateFormatConfig attribute.
voidsetRemotedir(String dir)
Sets the remote directory where files will be placed.
voidsetRetriesAllowed(String retriesAllowed)
Defines how many times to retry executing FTP command before giving up.
voidsetSeparator(String separator)
Sets the remote file separator character.
voidsetServer(String server)
Sets the FTP server to send files to.
voidsetServerLanguageCodeConfig(String serverLanguageCode)
Sets the serverLanguageCode attribute.
voidsetServerTimeZoneConfig(String serverTimeZoneId)
Sets the serverTimeZoneConfig attribute.
voidsetShortMonthNamesConfig(String shortMonthNames)
Sets the shortMonthNamesConfig attribute
voidsetSiteCommand(String siteCommand)
Sets the siteCommand attribute.
voidsetSkipFailedTransfers(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.
voidsetSystemTypeKey(FTPTask.FTPSystemType systemKey)
Sets the systemTypeKey attribute.
voidsetTimeDiffAuto(boolean timeDiffAuto)
"true" to find out automatically the time difference between local and remote machine.
voidsetTimeDiffMillis(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
voidsetTimestampGranularity(FTPTask.Granularity timestampGranularity)
Sets the timestampGranularity attribute
protected voidsetupFTPDelegate()
voidsetUmask(String theUmask)
Sets the default mask for file creation on a unix server.
voidsetUserid(String userid)
Sets the login user id to use on the specified server.
voidsetVerbose(boolean verbose)
Set to true to receive notification about each file as it is transferred.

Field Detail

ACTION_STRS

public static final String[] ACTION_STRS

ACTION_TARGET_STRS

public static final String[] ACTION_TARGET_STRS

CHMOD

public static final int CHMOD

COMPLETED_ACTION_STRS

public static final String[] COMPLETED_ACTION_STRS

DEFAULT_FTP_PORT

public static final int DEFAULT_FTP_PORT
Default port for FTP

DEL_FILES

public static final int DEL_FILES

GET_FILES

public static final int GET_FILES

LIST_FILES

public static final int LIST_FILES

MK_DIR

public static final int MK_DIR

RM_DIR

public static final int RM_DIR

SEND_FILES

public static final int SEND_FILES

SITE_CMD

public static final int SITE_CMD

Method Detail

addFileset

public void addFileset(FileSet set)
A set of files to upload or download

Parameters: set the set of files to be added to the list of files to be transferred.

checkAttributes

protected void checkAttributes()
Checks to see that all required parameters are set.

Throws: BuildException if the configuration is not valid.

createClasspath

public Path createClasspath()

execute

public void execute()
Runs the task.

Throws: BuildException if the task fails or is not configured correctly.

getAccount

public String getAccount()

getAction

public int getAction()

getChmod

public String getChmod()

getDefaultDateFormatConfig

public String getDefaultDateFormatConfig()

Returns: Returns the defaultDateFormatConfig.

getEnableRemoteVerification

public boolean getEnableRemoteVerification()

getFilesets

public Vector getFilesets()

getGranularityMillis

public long getGranularityMillis()

getInitialSiteCommand

public String getInitialSiteCommand()

getListing

public File getListing()

getPassword

public String getPassword()

getPort

public int getPort()

getRecentDateFormatConfig

public String getRecentDateFormatConfig()

Returns: Returns the recentDateFormatConfig.

getRemotedir

public String getRemotedir()

getRetriesAllowed

public int getRetriesAllowed()

getSeparator

public String getSeparator()

getServer

public String getServer()

getServerLanguageCodeConfig

public String getServerLanguageCodeConfig()

Returns: Returns the serverLanguageCodeConfig.

getServerTimeZoneConfig

public String getServerTimeZoneConfig()

Returns: Returns the serverTimeZoneConfig.

getShortMonthNamesConfig

public String getShortMonthNamesConfig()

Returns: Returns the shortMonthNamesConfig.

getSiteCommand

public String getSiteCommand()

getSystemTypeKey

public String getSystemTypeKey()

Returns: Returns the systemTypeKey.

getTimeDiffMillis

public long getTimeDiffMillis()

getTimestampGranularity

public FTPTask.Granularity getTimestampGranularity()

Returns: Returns the timestampGranularity.

getUmask

public String getUmask()

getUserid

public String getUserid()

isBinary

public boolean isBinary()

isConfigurationSet

public boolean isConfigurationSet()

isIgnoreNoncriticalErrors

public boolean isIgnoreNoncriticalErrors()

isNewer

public boolean isNewer()

isPassive

public boolean isPassive()

isPreserveLastModified

public boolean isPreserveLastModified()

isSkipFailedTransfers

public boolean isSkipFailedTransfers()

isTimeDiffAuto

public boolean isTimeDiffAuto()

isVerbose

public boolean isVerbose()

setAccount

public void setAccount(String pAccount)
Sets the login account to use on the specified server.

Parameters: pAccount the account name on remote system

Since: Ant 1.7

setAction

public void setAction(String action)

Deprecated: since 1.5.x. 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", "chmod", "list", and "site".

Parameters: action the FTP action to be performed.

Throws: BuildException if the action is not a valid action.

UNKNOWN: ignore="true"

setAction

public void setAction(FTPTask.Action action)
Sets the FTP action to be taken. Currently accepts "put", "get", "del", "mkdir", "chmod", "list", and "site".

Parameters: action the FTP action to be performed.

Throws: BuildException if the action is not a valid action.

setBinary

public void setBinary(boolean binary)
If true, uses binary mode, otherwise text mode (default is binary).

Parameters: 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.

Parameters: theMode unix style file mode for the files sent to the remote system.

setDefaultDateFormatConfig

public void setDefaultDateFormatConfig(String defaultDateFormat)
Sets the defaultDateFormatConfig attribute.

Parameters: defaultDateFormat configuration to be set, unless it is null or empty string, in which case ignored.

See Also: org.apache.commons.net.ftp.FTPClientConfig

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.

Parameters: depends if true only transfer newer files.

setEnableRemoteVerification

public void setEnableRemoteVerification(boolean b)
Whether to verify that data and control connections are connected to the same remote host.

Since: Ant 1.8.0

setGranularityMillis

public void setGranularityMillis(long granularity)

setIgnoreNoncriticalErrors

public void setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors)
set the flag to skip errors on directory creation. (and maybe later other server specific errors)

Parameters: ignoreNoncriticalErrors true if non-critical errors should not cause a failure.

setInitialSiteCommand

public void setInitialSiteCommand(String initialCommand)
Sets the initialSiteCommand attribute. This attribute names a site command that will be executed immediately after connection.

Parameters: initialCommand The initialSiteCommand to set.

setListing

public void setListing(File listing)
The output file for the "list" action. This attribute is ignored for any other actions.

Parameters: 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.

Parameters: 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.

Parameters: passive true is passive mode should be used.

setPassword

public void setPassword(String password)
Sets the login password for the given user id.

Parameters: password the password on the remote system.

setPort

public void setPort(int port)
Sets the FTP port used by the remote server.

Parameters: 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.

Parameters: preserveLastModified if true preserver modification times.

setRecentDateFormatConfig

public void setRecentDateFormatConfig(String recentDateFormat)
Sets the recentDateFormatConfig attribute.

Parameters: recentDateFormat configuration to be set, unless it is null or empty string, in which case ignored.

See Also: org.apache.commons.net.ftp.FTPClientConfig

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.

Parameters: dir the remote directory name.

setRetriesAllowed

public void setRetriesAllowed(String retriesAllowed)
Defines how many times to retry executing FTP command before giving up. Default is 0 - try once and if failure then give up.

Parameters: retriesAllowed number of retries to allow. -1 means keep trying forever. "forever" may also be specified as a synonym for -1.

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.

Parameters: separator the file separator on the remote system.

setServer

public void setServer(String server)
Sets the FTP server to send files to.

Parameters: server the remote server name.

setServerLanguageCodeConfig

public void setServerLanguageCodeConfig(String serverLanguageCode)
Sets the serverLanguageCode attribute.

Parameters: serverLanguageCode configuration to be set, unless it is null or empty string, in which case ignored.

See Also: org.apache.commons.net.ftp.FTPClientConfig

setServerTimeZoneConfig

public void setServerTimeZoneConfig(String serverTimeZoneId)
Sets the serverTimeZoneConfig attribute.

Parameters: serverTimeZoneId configuration to be set, unless it is null or empty string, in which case ignored.

See Also: org.apache.commons.net.ftp.FTPClientConfig

setShortMonthNamesConfig

public void setShortMonthNamesConfig(String shortMonthNames)
Sets the shortMonthNamesConfig attribute

Parameters: shortMonthNames configuration to be set, unless it is null or empty string, in which case ignored.

See Also: org.apache.commons.net.ftp.FTPClientConfig

setSiteCommand

public void setSiteCommand(String siteCommand)
Sets the siteCommand attribute. This attribute names the command that will be executed if the action is "site".

Parameters: siteCommand The siteCommand to set.

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.

Parameters: skipFailedTransfers true if failures in transfers are ignored.

setSystemTypeKey

public void setSystemTypeKey(FTPTask.FTPSystemType systemKey)
Sets the systemTypeKey attribute. Method for setting FTPClientConfig remote system key.

Parameters: systemKey the key to be set - BUT if blank the default value of null (which signifies "autodetect") will be kept.

See Also: org.apache.commons.net.ftp.FTPClientConfig

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.

Parameters: timeDiffAuto true = find automatically the time diff

Since: ant 1.6

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

Parameters: timeDiffMillis number of milliseconds

Since: ant 1.6

setTimestampGranularity

public void setTimestampGranularity(FTPTask.Granularity timestampGranularity)
Sets the timestampGranularity attribute

Parameters: timestampGranularity The timestampGranularity to set.

setupFTPDelegate

protected void setupFTPDelegate()

setUmask

public void setUmask(String theUmask)
Sets the default mask for file creation on a unix server.

Parameters: 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.

Parameters: userid remote system userid.

setVerbose

public void setVerbose(boolean verbose)
Set to true to receive notification about each file as it is transferred.

Parameters: verbose true if verbose notifications are required.