Class SFTPRepository
- java.lang.Object
-
- org.apache.ivy.plugins.repository.AbstractRepository
-
- org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository
-
- org.apache.ivy.plugins.repository.sftp.SFTPRepository
-
- All Implemented Interfaces:
Repository
public class SFTPRepository extends AbstractSshBasedRepository
SFTP Repository, allow to use a repository accessed by sftp protocol. It supports all operations: get, put and list. It relies on jsch for sftp handling, and thus is compatible with sftp version 0, 1, 2 and 3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSFTPRepository.MyProgressMonitor
-
Field Summary
Fields Modifier and Type Field Description private static longMILLIS_PER_SECOND
-
Constructor Summary
Constructors Constructor Description SFTPRepository()SFTPRepository(TimeoutConstraint timeoutConstraint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancheckExistence(java.lang.String file, com.jcraft.jsch.ChannelSftp channel)Checks the existence for a remote filevoidget(java.lang.String source, java.io.File destination)Fetch a resource from the repository.private java.lang.StringgetPath(java.lang.String sftpURI)protected java.lang.StringgetRepositoryScheme()ResourcegetResource(java.lang.String source)Return the resource associated with a specified identifier.private com.jcraft.jsch.ChannelSftpgetSftpChannel(java.lang.String pathOrUri)Establish the connection to the server if not yet connected, and listen to ivy events for closing connection when resolve is finished.java.util.List<java.lang.String>list(java.lang.String parent)Return a listing of resources namesprivate voidmkdirs(java.lang.String directory, com.jcraft.jsch.ChannelSftp c)java.io.InputStreamopenStream(SFTPResource resource)voidput(java.io.File source, java.lang.String destination, boolean overwrite)ResourceresolveResource(java.lang.String path)This method is similar to getResource, except that the returned resource is fully initialized (resolved in the sftp repository), and that the given string is a full remote path-
Methods inherited from class org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository
getHost, getKeyFile, getKeyFilePassword, getPassFile, getPort, getSession, getSshConfig, getUser, getUserPassword, isAllowedAgentUse, releaseSession, setAllowedAgentUse, setHost, setKeyFile, setKeyFilePassword, setPassFile, setPort, setSshConfig, setUser, setUserPassword
-
Methods inherited from class org.apache.ivy.plugins.repository.AbstractRepository
addTransferListener, fireTransferCompleted, fireTransferCompleted, fireTransferError, fireTransferError, fireTransferEvent, fireTransferInitiated, fireTransferProgress, fireTransferStarted, fireTransferStarted, getFileSeparator, getName, getTimeoutConstraint, hasTransferListener, put, removeTransferListener, setName, standardize, toString
-
-
-
-
Field Detail
-
MILLIS_PER_SECOND
private static final long MILLIS_PER_SECOND
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SFTPRepository
public SFTPRepository()
-
SFTPRepository
public SFTPRepository(TimeoutConstraint timeoutConstraint)
-
-
Method Detail
-
getResource
public Resource getResource(java.lang.String source)
Description copied from interface:RepositoryReturn the resource associated with a specified identifier. If the resource does not exist, it should return a Resource with exists() returning false. An IOException should only be thrown when a real IO problem occurs, like the impossibility to connect to a server.- Parameters:
source- A string identifying the resource.- Returns:
- The resource associated with the resource identifier.
-
resolveResource
public Resource resolveResource(java.lang.String path)
This method is similar to getResource, except that the returned resource is fully initialized (resolved in the sftp repository), and that the given string is a full remote path- Parameters:
path- the full remote path in the repository of the resource- Returns:
- a fully initialized resource, able to answer to all its methods without needing any further connection
-
openStream
public java.io.InputStream openStream(SFTPResource resource) throws java.io.IOException
- Throws:
java.io.IOException
-
get
public void get(java.lang.String source, java.io.File destination) throws java.io.IOExceptionDescription copied from interface:RepositoryFetch a resource from the repository.- Parameters:
source- A string identifying the resource to be fetched.destination- Where to place the fetched resource.- Throws:
java.io.IOException- On retrieval failure.
-
put
public void put(java.io.File source, java.lang.String destination, boolean overwrite) throws java.io.IOException- Overrides:
putin classAbstractRepository- Throws:
java.io.IOException
-
mkdirs
private void mkdirs(java.lang.String directory, com.jcraft.jsch.ChannelSftp c) throws com.jcraft.jsch.SftpException- Throws:
com.jcraft.jsch.SftpException
-
getPath
private java.lang.String getPath(java.lang.String sftpURI) throws java.net.URISyntaxException- Throws:
java.net.URISyntaxException
-
list
public java.util.List<java.lang.String> list(java.lang.String parent) throws java.io.IOExceptionDescription copied from interface:RepositoryReturn a listing of resources names- Parameters:
parent- The parent directory from which to generate the listing.- Returns:
- A listing of the parent directory's file content
- Throws:
java.io.IOException- On listing failure.
-
checkExistence
private boolean checkExistence(java.lang.String file, com.jcraft.jsch.ChannelSftp channel)Checks the existence for a remote file- Parameters:
file- to checkchannel- to use- Returns:
- true if file exists, false otherwise
-
getSftpChannel
private com.jcraft.jsch.ChannelSftp getSftpChannel(java.lang.String pathOrUri) throws java.io.IOExceptionEstablish the connection to the server if not yet connected, and listen to ivy events for closing connection when resolve is finished. Not meant to be used in multi threaded environment.- Returns:
- the ChannelSftp with which a connection is established
- Throws:
java.io.IOException- if any connection problem occurs
-
getRepositoryScheme
protected java.lang.String getRepositoryScheme()
- Specified by:
getRepositorySchemein classAbstractSshBasedRepository
-
-