Package com.sshtools.ant
Class Sftp
java.lang.Object
com.sshtools.ant.SshSubTask
com.sshtools.ant.Sftp
Basic SFTP client. Performs the following actions:
- put - send files to a remote server. This is the default action.
- get - retreive files from a remote server.
- del - delete files from a remote server.
- chmod - changes the mode of files on a remote server.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
an action to perform, one of "send", "put", "recv", "get", "del", "delete", "list", "mkdir", "chmod"protected class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String[]
protected static final int
protected static final String[]
protected static final int
protected static final int
protected static final int
protected static final int
Fields inherited from class com.sshtools.ant.SshSubTask
parent, taskString
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFileset
(org.apache.tools.ant.types.FileSet set) A set of files to upload or downloadprotected void
Checks to see that all required parameters are set.protected void
chmod
(SftpClient sftp, String filename) protected void
createParents
(SftpClient sftp, String filename) Creates all parent directories specified in a complete relative pathname.protected void
delFile
(SftpClient sftp, String filename) Delete a file from the remote host.void
Runs the task.protected void
executeSFTPTask
(SshClient ssh) protected void
getFile
(SftpClient sftp, String dir, String filename) Retrieve a single file to the remote host.protected boolean
isUpToDate
(SftpClient sftp, File localFile, String remoteFile) Checks to see if the remote file is current as compared with the local file.protected void
makeRemoteDir
(SftpClient sftp, String dir) Create the specified directory on the remote host.protected String
resolveFile
(String file) Correct a file path to correspond to the remote host requirements.protected void
sendFile
(SftpClient sftp, String dir, String filename) Sends a single file to the remote host.void
setAction
(Sftp.Action action) Deprecated.void
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
setNewer
(boolean newer) A synonym for depends.void
setRemotedir
(String remotedir) Sets the remote working directoryvoid
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
setVerbose
(boolean verbose) Set to true to receive notification about each file as it is transferred.protected void
transferFiles
(SftpClient sftp) Sends all files specified by the configured filesets to the remote server.protected int
transferFiles
(SftpClient sftp, org.apache.tools.ant.types.FileSet fs) For each file in the fileset, do the appropriate action: send, get, delete, or list.Methods inherited from class com.sshtools.ant.SshSubTask
log, log, setParent
-
Field Details
-
SEND_FILES
protected static final int SEND_FILES- See Also:
-
GET_FILES
protected static final int GET_FILES- See Also:
-
DEL_FILES
protected static final int DEL_FILES- See Also:
-
MK_DIR
protected static final int MK_DIR- See Also:
-
CHMOD
protected static final int CHMOD- See Also:
-
ACTION_STRS
-
COMPLETED_ACTION_STRS
-
-
Constructor Details
-
Sftp
public Sftp()
-
-
Method Details
-
setVerbose
public void setVerbose(boolean verbose) Set to true to receive notification about each file as it is transferred. -
setRemotedir
Sets the remote working directory -
setNewer
public void setNewer(boolean newer) A synonym for depends. Set to true to transmit only new or changed files. -
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. -
setChmod
Sets the file permission mode (Unix only) for files sent to the server. -
addFileset
public void addFileset(org.apache.tools.ant.types.FileSet set) A set of files to upload or download -
setAction
Deprecated.Sets the FTP action to be taken. Currently accepts "put", "get", "del", "mkdir", "chmod" and "list".- Throws:
org.apache.tools.ant.BuildException
-
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. -
setIgnoreNoncriticalErrors
public void setIgnoreNoncriticalErrors(boolean ignoreNoncriticalErrors) set the flag to skip errors on directory creation. (and maybe later other server specific errors) -
checkConfiguration
protected void checkConfiguration() throws org.apache.tools.ant.BuildExceptionChecks to see that all required parameters are set.- Throws:
org.apache.tools.ant.BuildException
-
transferFiles
protected int transferFiles(SftpClient sftp, org.apache.tools.ant.types.FileSet fs) throws IOException, org.apache.tools.ant.BuildException For each file in the fileset, do the appropriate action: send, get, delete, or list.- Throws:
IOException
org.apache.tools.ant.BuildException
-
transferFiles
protected void transferFiles(SftpClient sftp) throws IOException, org.apache.tools.ant.BuildException Sends all files specified by the configured filesets to the remote server.- Throws:
IOException
org.apache.tools.ant.BuildException
-
resolveFile
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. -
createParents
protected void createParents(SftpClient sftp, String filename) throws IOException, org.apache.tools.ant.BuildException Creates all parent directories specified in a complete relative pathname. Attempts to create existing directories will not cause errors.- Throws:
IOException
org.apache.tools.ant.BuildException
-
isUpToDate
protected boolean isUpToDate(SftpClient sftp, File localFile, String remoteFile) throws IOException, org.apache.tools.ant.BuildException Checks to see if the remote file is current as compared with the local file. Returns true if the remote file is up to date.- Throws:
IOException
org.apache.tools.ant.BuildException
-
sendFile
protected void sendFile(SftpClient sftp, String dir, String filename) throws IOException, org.apache.tools.ant.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.- Throws:
IOException
org.apache.tools.ant.BuildException
-
delFile
protected void delFile(SftpClient sftp, String filename) throws IOException, org.apache.tools.ant.BuildException Delete a file from the remote host.- Throws:
IOException
org.apache.tools.ant.BuildException
-
chmod
protected void chmod(SftpClient sftp, String filename) throws IOException, org.apache.tools.ant.BuildException - Throws:
IOException
org.apache.tools.ant.BuildException
-
getFile
protected void getFile(SftpClient sftp, String dir, String filename) throws IOException, org.apache.tools.ant.BuildException Retrieve a single file to 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.
- Throws:
IOException
org.apache.tools.ant.BuildException
-
makeRemoteDir
protected void makeRemoteDir(SftpClient sftp, String dir) throws org.apache.tools.ant.BuildException Create the specified directory on the remote host.- Parameters:
sftp
- The SFTP client connectiondir
- The directory to create- Throws:
org.apache.tools.ant.BuildException
-
execute
Runs the task.- Overrides:
execute
in classSshSubTask
- Throws:
org.apache.tools.ant.BuildException
-
executeSFTPTask
- Throws:
org.apache.tools.ant.BuildException
-