Class VsftpRepository
- java.lang.Object
-
- org.apache.ivy.plugins.repository.AbstractRepository
-
- org.apache.ivy.plugins.repository.vsftp.VsftpRepository
-
- All Implemented Interfaces:
Repository
public class VsftpRepository extends AbstractRepository
Repository using SecureCRT vsftp command line program to access an sftp repository This is especially useful to leverage the gssapi authentication supported by SecureCRT. In cases where usual sftp is enough, prefer the 100% java solution of sftp repository. This requires SecureCRT to be in the PATH. Tested with SecureCRT 5.0.5
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringauthenticationprivate java.lang.ThreadconnectionCleanerprivate static intDEFAULT_READ_TIMEOUTprivate static intDEFAULT_REUSE_CONNECTION_TIMEprivate static intDISCONNECT_COMMAND_TIMEOUTprivate java.io.Readererrprivate static intERROR_SLEEP_TIMEprivate java.lang.StringBuildererrorsprivate longerrorsLastUpdateTimeprivate java.lang.ThreaderrorsReaderprivate static java.text.SimpleDateFormatFORMATprivate static intGET_JOIN_MAX_TIMEprivate java.lang.Stringhostprivate java.io.Readerinprivate booleaninCommandprivate Ivyivyprivate longlastCommandprivate static intLS_DATE_INDEX1private static intLS_DATE_INDEX2private static intLS_DATE_INDEX3private static intLS_DATE_INDEX4private static intLS_PARTS_NUMBERprivate static intLS_SIZE_INDEXprivate static intMAX_READ_PROMPT_ATTEMPTprivate static intMAX_READER_ALIVE_ATTEMPTprivate java.io.PrintWriteroutprivate java.lang.Processprocessprivate static java.lang.StringPROMPTprivate static intPROMPT_SLEEP_TIMEprivate static intREADER_ALIVE_SLEEP_TIMEprivate longreadTimeoutprivate static intREUSE_CONNECTION_SLEEP_TIMEprivate longreuseConnectionprivate java.lang.Stringusername
-
Constructor Summary
Constructors Constructor Description VsftpRepository()VsftpRepository(TimeoutConstraint timeoutConstraint)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckInterrupted()private static java.lang.StringBuilderchomp(java.lang.StringBuilder str)private voidcleanup()Called whenever an api level method endprivate voidcleanup(java.lang.Exception ex)Called whenever an api level method endprivate voidcloseConnection()private booleandirExists(java.lang.String dir)voiddisconnect()protected voidensureConnectionOpened()private voidexec(java.lang.String command)voidget(java.lang.String source, java.io.File destination)Fetch a resource from the repository.java.lang.StringgetAuthentication()protected java.lang.StringgetConnectionCommand()protected java.util.regex.PatterngetExpectedDownloadMessage(java.lang.String source, java.io.File to)protected java.util.regex.PatterngetExpectedRemoveMessage(java.lang.String destination)protected java.util.regex.PatterngetExpectedUploadMessage(java.io.File source, java.lang.String to)java.lang.StringgetHost()protected ResourcegetInitResource(java.lang.String source)longgetReadTimeout()ResourcegetResource(java.lang.String source)Return the resource associated with a specified identifier.protected java.lang.StringgetSingleCommand(java.lang.String command)java.lang.StringgetUsername()private voidinitIvy()java.util.List<java.lang.String>list(java.lang.String parent)Return a listing of resources namesprotected ResourcelslToResource(java.lang.String file, java.lang.String responseLine)Parses a ls -l line and transforms it in a resourceprivate voidmkdirs(java.lang.String destDir)voidput(java.io.File source, java.lang.String destination, boolean overwrite)protected java.lang.StringreadResponse(boolean sendErrorAsResponse)protected java.lang.StringreadResponse(boolean sendErrorAsResponse, long timeout)protected java.lang.StringsendCommand(java.lang.String command)protected java.lang.StringsendCommand(java.lang.String command, boolean sendErrorAsResponse)protected java.lang.StringsendCommand(java.lang.String command, boolean sendErrorAsResponse, boolean single)protected java.lang.StringsendCommand(java.lang.String command, boolean sendErrorAsResponse, boolean single, long timeout)protected java.lang.StringsendCommand(java.lang.String command, boolean sendErrorAsResponse, long timeout)protected voidsendCommand(java.lang.String command, java.util.regex.Pattern expectedResponse)protected voidsendCommand(java.lang.String command, java.util.regex.Pattern expectedResponse, long timeout)The behaviour of vsftp with some commands is to log the resulting message on the error stream, even if everything is ok.private voidsendSingleCommand(java.lang.String command)voidsetAuthentication(java.lang.String authentication)voidsetHost(java.lang.String host)voidsetReadTimeout(long readTimeout)voidsetReuseConnection(long time)Sets the reuse connection time.voidsetUsername(java.lang.String username)java.lang.StringtoString()private voidupdateLastCommandTime()-
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
-
-
-
-
Field Detail
-
LS_DATE_INDEX4
private static final int LS_DATE_INDEX4
- See Also:
- Constant Field Values
-
LS_DATE_INDEX3
private static final int LS_DATE_INDEX3
- See Also:
- Constant Field Values
-
LS_DATE_INDEX2
private static final int LS_DATE_INDEX2
- See Also:
- Constant Field Values
-
LS_DATE_INDEX1
private static final int LS_DATE_INDEX1
- See Also:
- Constant Field Values
-
LS_SIZE_INDEX
private static final int LS_SIZE_INDEX
- See Also:
- Constant Field Values
-
LS_PARTS_NUMBER
private static final int LS_PARTS_NUMBER
- See Also:
- Constant Field Values
-
DISCONNECT_COMMAND_TIMEOUT
private static final int DISCONNECT_COMMAND_TIMEOUT
- See Also:
- Constant Field Values
-
REUSE_CONNECTION_SLEEP_TIME
private static final int REUSE_CONNECTION_SLEEP_TIME
- See Also:
- Constant Field Values
-
READER_ALIVE_SLEEP_TIME
private static final int READER_ALIVE_SLEEP_TIME
- See Also:
- Constant Field Values
-
MAX_READER_ALIVE_ATTEMPT
private static final int MAX_READER_ALIVE_ATTEMPT
- See Also:
- Constant Field Values
-
ERROR_SLEEP_TIME
private static final int ERROR_SLEEP_TIME
- See Also:
- Constant Field Values
-
PROMPT_SLEEP_TIME
private static final int PROMPT_SLEEP_TIME
- See Also:
- Constant Field Values
-
MAX_READ_PROMPT_ATTEMPT
private static final int MAX_READ_PROMPT_ATTEMPT
- See Also:
- Constant Field Values
-
GET_JOIN_MAX_TIME
private static final int GET_JOIN_MAX_TIME
- See Also:
- Constant Field Values
-
DEFAULT_REUSE_CONNECTION_TIME
private static final int DEFAULT_REUSE_CONNECTION_TIME
- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT
private static final int DEFAULT_READ_TIMEOUT
- See Also:
- Constant Field Values
-
PROMPT
private static final java.lang.String PROMPT
- See Also:
- Constant Field Values
-
FORMAT
private static final java.text.SimpleDateFormat FORMAT
-
host
private java.lang.String host
-
username
private java.lang.String username
-
authentication
private java.lang.String authentication
-
in
private java.io.Reader in
-
err
private java.io.Reader err
-
out
private java.io.PrintWriter out
-
errors
private volatile java.lang.StringBuilder errors
-
readTimeout
private long readTimeout
-
reuseConnection
private long reuseConnection
-
lastCommand
private volatile long lastCommand
-
inCommand
private volatile boolean inCommand
-
process
private java.lang.Process process
-
connectionCleaner
private java.lang.Thread connectionCleaner
-
errorsReader
private java.lang.Thread errorsReader
-
errorsLastUpdateTime
private volatile long errorsLastUpdateTime
-
ivy
private Ivy ivy
-
-
Constructor Detail
-
VsftpRepository
public VsftpRepository()
-
VsftpRepository
public VsftpRepository(TimeoutConstraint timeoutConstraint)
-
-
Method Detail
-
getResource
public Resource getResource(java.lang.String source) throws java.io.IOException
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.
- Throws:
java.io.IOException- On error while trying to get resource.
-
initIvy
private void initIvy()
-
getInitResource
protected Resource getInitResource(java.lang.String source) 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.
-
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.
-
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 destDir) throws java.io.IOException- Throws:
java.io.IOException
-
dirExists
private boolean dirExists(java.lang.String dir) throws java.io.IOException- Throws:
java.io.IOException
-
sendCommand
protected java.lang.String sendCommand(java.lang.String command) throws java.io.IOException- Throws:
java.io.IOException
-
sendCommand
protected void sendCommand(java.lang.String command, java.util.regex.Pattern expectedResponse) throws java.io.IOException- Throws:
java.io.IOException
-
sendCommand
protected void sendCommand(java.lang.String command, java.util.regex.Pattern expectedResponse, long timeout) throws java.io.IOExceptionThe behaviour of vsftp with some commands is to log the resulting message on the error stream, even if everything is ok. So it's quite difficult if there was an error or not. Hence we compare the response with the expected message and deal with it. The problem is that this is very specific to the version of vsftp used for the test, That's why expected messages are obtained using overriddable protected methods.- Parameters:
command- StringexpectedResponse- Patterntimeout- long- Throws:
java.io.IOException- if something goes wrong
-
sendCommand
protected java.lang.String sendCommand(java.lang.String command, boolean sendErrorAsResponse) throws java.io.IOException- Throws:
java.io.IOException
-
sendCommand
protected java.lang.String sendCommand(java.lang.String command, boolean sendErrorAsResponse, boolean single) throws java.io.IOException- Throws:
java.io.IOException
-
sendCommand
protected java.lang.String sendCommand(java.lang.String command, boolean sendErrorAsResponse, long timeout) throws java.io.IOException- Throws:
java.io.IOException
-
sendCommand
protected java.lang.String sendCommand(java.lang.String command, boolean sendErrorAsResponse, boolean single, long timeout) throws java.io.IOException- Throws:
java.io.IOException
-
readResponse
protected java.lang.String readResponse(boolean sendErrorAsResponse) throws java.io.IOException- Throws:
java.io.IOException
-
readResponse
protected java.lang.String readResponse(boolean sendErrorAsResponse, long timeout) throws java.io.IOException- Throws:
java.io.IOException
-
sendSingleCommand
private void sendSingleCommand(java.lang.String command) throws java.io.IOException- Throws:
java.io.IOException
-
ensureConnectionOpened
protected void ensureConnectionOpened() throws java.io.IOException- Throws:
java.io.IOException
-
updateLastCommandTime
private void updateLastCommandTime()
-
exec
private void exec(java.lang.String command) throws java.io.IOException- Throws:
java.io.IOException
-
checkInterrupted
private void checkInterrupted()
-
cleanup
private void cleanup(java.lang.Exception ex)
Called whenever an api level method end
-
cleanup
private void cleanup()
Called whenever an api level method end
-
disconnect
public void disconnect()
-
closeConnection
private void closeConnection()
-
lslToResource
protected Resource lslToResource(java.lang.String file, java.lang.String responseLine)
Parses a ls -l line and transforms it in a resource- Parameters:
file- dittoresponseLine- ditto- Returns:
- Resource
-
getSingleCommand
protected java.lang.String getSingleCommand(java.lang.String command)
-
getConnectionCommand
protected java.lang.String getConnectionCommand()
-
getExpectedDownloadMessage
protected java.util.regex.Pattern getExpectedDownloadMessage(java.lang.String source, java.io.File to)
-
getExpectedRemoveMessage
protected java.util.regex.Pattern getExpectedRemoveMessage(java.lang.String destination)
-
getExpectedUploadMessage
protected java.util.regex.Pattern getExpectedUploadMessage(java.io.File source, java.lang.String to)
-
getAuthentication
public java.lang.String getAuthentication()
-
setAuthentication
public void setAuthentication(java.lang.String authentication)
-
getHost
public java.lang.String getHost()
-
setHost
public void setHost(java.lang.String host)
-
getUsername
public java.lang.String getUsername()
-
setUsername
public void setUsername(java.lang.String username)
-
chomp
private static java.lang.StringBuilder chomp(java.lang.StringBuilder str)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractRepository
-
setReuseConnection
public void setReuseConnection(long time)
Sets the reuse connection time. The same connection will be reused if the time here does not last between two commands. O indicates that the connection should never be reused- Parameters:
time- long
-
getReadTimeout
public long getReadTimeout()
-
setReadTimeout
public void setReadTimeout(long readTimeout)
-
-