org.apache.tools.ant.taskdefs.optional.netClass FTPTaskMirrorImpl
- java.lang.Object
- org.apache.tools.ant.taskdefs.optional.net.FTPTaskMirrorImpl
- All Implemented Interfaces:
- FTPTaskMirror
public class FTPTaskMirrorImpl extends java.lang.Object implements FTPTaskMirror
Nested Class Summary
Nested Classes Modifier and Type Class and Description protected class
FTPTaskMirrorImpl.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 falseprotected static class
FTPTaskMirrorImpl.FTPFileProxy
internal class providing a File-like interface to some of the information available from the FTP server
Constructor Summary
Constructors Constructor and Description FTPTaskMirrorImpl(FTPTask task)
Constructor.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description 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.void
doFTP()
protected void
doSiteCommand(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String theCMD)
Sends a site command to the ftp serverprotected void
executeRetryable(RetryHandler h, Retryable r, java.lang.String descr)
Executable a retryable object.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.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.
Constructor Detail
FTPTaskMirrorImpl
public FTPTaskMirrorImpl(FTPTask task)Constructor.
- Parameters:
task
- the FTPTask that uses this mirror.
Method Detail
executeRetryable
protected void executeRetryable(RetryHandler h, Retryable r, java.lang.String descr) throws java.io.IOExceptionExecutable a retryable object.
- Parameters:
h
- the retry handler.r
- the object that should be retried until it succeeds or the number of retries is reached.descr
- a description of the command that is being run.- Throws:
java.io.IOException
- if there is a problem.
transferFiles
protected int transferFiles(org.apache.commons.net.ftp.FTPClient ftp, FileSet fs) throws java.io.IOException, BuildExceptionFor each file in the fileset, do the appropriate action: send, get, delete, or list.
- Parameters:
ftp
- the FTPClient instance used to perform FTP actionsfs
- the fileset on which the actions are performed.- Returns:
- the number of files to be transferred.
- Throws:
java.io.IOException
- if there is a problem reading a fileBuildException
- if there is a problem in the configuration.
transferFiles
protected void transferFiles(org.apache.commons.net.ftp.FTPClient ftp) throws java.io.IOException, BuildExceptionSends all files specified by the configured filesets to the remote server.
- Parameters:
ftp
- the FTPClient instance used to perform FTP actions- Throws:
java.io.IOException
- if there is a problem reading a fileBuildException
- if there is a problem in the configuration.
resolveFile
protected java.lang.String resolveFile(java.lang.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 theseparator
task parameter. No attempt is made to determine what syntax is appropriate for the remote host.
- Parameters:
file
- the remote file name to be resolved- Returns:
- the filename as it will appear on the server.
createParents
protected void createParents(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String filename) throws java.io.IOException, BuildExceptionCreates all parent directories specified in a complete relative pathname. Attempts to create existing directories will not cause errors.
- Parameters:
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.- Throws:
java.io.IOException
- under non documented circumstancesBuildException
- if it is impossible to cd to a remote directory
isUpToDate
protected boolean isUpToDate(org.apache.commons.net.ftp.FTPClient ftp, java.io.File localFile, java.lang.String remoteFile) throws java.io.IOException, BuildExceptionChecks to see if the remote file is current as compared with the local file. Returns true if the target file is up to date.
- Parameters:
ftp
- ftpclientlocalFile
- local fileremoteFile
- remote file- Returns:
- true if the target file is up to date
- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- if the date of the remote files cannot be found and the action is GET_FILES
doSiteCommand
protected void doSiteCommand(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String theCMD) throws java.io.IOException, BuildExceptionSends a site command to the ftp server
- Parameters:
ftp
- ftp clienttheCMD
- command to execute- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- in unknown circumstances
sendFile
protected void sendFile(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dir, java.lang.String filename) throws java.io.IOException, BuildExceptionSends 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.
- Parameters:
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- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- in unknown circumstances
delFile
protected void delFile(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String filename) throws java.io.IOException, BuildExceptionDelete a file from the remote host.
- Parameters:
ftp
- ftp clientfilename
- file to delete- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- if skipFailedTransfers is set to false and the deletion could not be done
rmDir
protected void rmDir(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dirname) throws java.io.IOException, BuildExceptionDelete a directory, if empty, from the remote host.
- Parameters:
ftp
- ftp clientdirname
- directory to delete- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- if skipFailedTransfers is set to false and the deletion could not be done
getFile
protected void getFile(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dir, java.lang.String filename) throws java.io.IOException, BuildExceptionRetrieve a single file from the remote host.filename
may contain a relative path specification.The file 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.
- Parameters:
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)- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- if skipFailedTransfers is false and the file cannot be retrieved.
listFile
protected void listFile(org.apache.commons.net.ftp.FTPClient ftp, java.io.BufferedWriter bw, java.lang.String filename) throws java.io.IOException, BuildExceptionList 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.
- Parameters:
ftp
- ftp clientbw
- buffered writerfilename
- the directory one wants to list- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- in unknown circumstances
makeRemoteDir
protected void makeRemoteDir(org.apache.commons.net.ftp.FTPClient ftp, java.lang.String dir) throws java.io.IOException, BuildExceptionCreate the specified directory on the remote host.
- Parameters:
ftp
- The FTP client connectiondir
- The directory to create (format must be correct for host type)- Throws:
java.io.IOException
- in unknown circumstancesBuildException
- 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
doFTP
public void doFTP() throws BuildException
- Specified by:
doFTP
in interfaceFTPTaskMirror
- Throws:
BuildException