Package adams.core.io.lister
Class FtpDirectoryLister
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.io.lister.AbstractDirectoryLister
-
- adams.core.io.lister.AbstractRecursiveDirectoryLister
-
- adams.core.io.lister.FtpDirectoryLister
-
- All Implemented Interfaces:
DirectoryLister
,RecursiveDirectoryLister
,LoggingLevelHandler
,LoggingSupporter
,PasswordSupporter
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,Serializable
,EventListener
,org.apache.commons.net.ProtocolCommandListener
public class FtpDirectoryLister extends AbstractRecursiveDirectoryLister implements org.apache.commons.net.ProtocolCommandListener, PasswordSupporter
Lists files/dirs on a remote server using FTP. The provided client provider takes precedence of the parameters.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.net.ftp.FTPClient
m_Client
the FTP session.protected String
m_Host
the FTP host.protected BasePassword
m_Password
the FTP password to use.protected boolean
m_UseBinaryMode
whether to use binary file transfer mode.protected boolean
m_UsePassiveMode
whether to use passive mode.protected String
m_User
the FTP user to use.-
Fields inherited from class adams.core.io.lister.AbstractRecursiveDirectoryLister
m_MaxDepth, m_Recursive
-
Fields inherited from class adams.core.io.lister.AbstractDirectoryLister
m_ListDirs, m_ListFiles, m_MaxItems, m_RegExp, m_SortDescending, m_Sorting, m_Stopped, m_WatchDir
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description FtpDirectoryLister()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
disconnect(org.apache.commons.net.ftp.FTPClient client)
Disconnects the SSH session, if necessary.org.apache.commons.net.ftp.FTPClient
getClient()
Returns the current session provider.String
getHost()
Returns the host to connect to.BasePassword
getPassword()
Returns the FTP password to use.boolean
getUseBinaryMode()
Returns whether binary mode is used.boolean
getUsePassiveMode()
Returns whether passive mode is used.String
getUser()
Returns the FTP user name to use.boolean
hasParentDirectory()
Returns whether the watch directory has a parent directory.boolean
isLocal()
Returns whether the directory lister operates locally or remotely.String[]
list()
Returns the list of files/directories in the watched directory.FtpFileObject[]
listObjects()
Returns the list of files/directories in the watched directory.protected org.apache.commons.net.ftp.FTPClient
newClient()
Returns a new client for the host defined in the options.FtpFileObject
newDirectory(String dir)
Returns a new directory relative to the watch directory.FtpFileObject
newDirectory(String parent, String dir)
Returns a new directory generated from parent and sub-directory.void
protocolCommandSent(org.apache.commons.net.ProtocolCommandEvent event)
This method is invoked by a ProtocolCommandEvent source after sending a protocol command to a server.void
protocolReplyReceived(org.apache.commons.net.ProtocolCommandEvent event)
This method is invoked by a ProtocolCommandEvent source after receiving a reply from a server.List<FtpFileObject>
search(org.apache.commons.net.ftp.FTPClient client)
Returns the list of files/directories in the watched directory.protected void
search(org.apache.commons.net.ftp.FTPClient client, String current, List<SortContainer> files, int depth)
Performs the recursive search.void
setClient(org.apache.commons.net.ftp.FTPClient value)
Sets the client to use.void
setHost(String value)
Sets the host to connect to.void
setPassword(BasePassword value)
Sets the FTP password to use.void
setUseBinaryMode(boolean value)
Sets whether to use binary mode.void
setUsePassiveMode(boolean value)
Sets whether to use passive mode.void
setUser(String value)
Sets the FTP user to use.-
Methods inherited from class adams.core.io.lister.AbstractRecursiveDirectoryLister
getMaxDepth, getRecursive, setMaxDepth, setRecursive, toString
-
Methods inherited from class adams.core.io.lister.AbstractDirectoryLister
getDebug, getListDirs, getListFiles, getMaxItems, getRegExp, getSortDescending, getSorting, getWatchDir, isStopped, setDebug, setListDirs, setListFiles, setMaxItems, setRegExp, setSortDescending, setSorting, setWatchDir, stopExecution
-
Methods inherited from class adams.core.logging.CustomLoggingLevelObject
setLoggingLevel
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.io.lister.DirectoryLister
getListDirs, getListFiles, getMaxItems, getRegExp, getSortDescending, getSorting, getWatchDir, setListDirs, setListFiles, setMaxItems, setRegExp, setSortDescending, setSorting, setWatchDir
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.Stoppable
stopExecution
-
Methods inherited from interface adams.core.StoppableWithFeedback
isStopped
-
-
-
-
Field Detail
-
m_Host
protected String m_Host
the FTP host.
-
m_User
protected String m_User
the FTP user to use.
-
m_Password
protected BasePassword m_Password
the FTP password to use.
-
m_UsePassiveMode
protected boolean m_UsePassiveMode
whether to use passive mode.
-
m_UseBinaryMode
protected boolean m_UseBinaryMode
whether to use binary file transfer mode.
-
m_Client
protected transient org.apache.commons.net.ftp.FTPClient m_Client
the FTP session.
-
-
Method Detail
-
setHost
public void setHost(String value)
Sets the host to connect to.- Parameters:
value
- the host name/ip
-
getHost
public String getHost()
Returns the host to connect to.- Returns:
- the host name/ip
-
setUser
public void setUser(String value)
Sets the FTP user to use.- Parameters:
value
- the user name
-
getUser
public String getUser()
Returns the FTP user name to use.- Returns:
- the user name
-
setPassword
public void setPassword(BasePassword value)
Sets the FTP password to use.- Specified by:
setPassword
in interfacePasswordSupporter
- Parameters:
value
- the password
-
getPassword
public BasePassword getPassword()
Returns the FTP password to use.- Specified by:
getPassword
in interfacePasswordSupporter
- Returns:
- the password
-
setUsePassiveMode
public void setUsePassiveMode(boolean value)
Sets whether to use passive mode.- Parameters:
value
- if true passive mode is used
-
getUsePassiveMode
public boolean getUsePassiveMode()
Returns whether passive mode is used.- Returns:
- true if passive mode is used
-
setUseBinaryMode
public void setUseBinaryMode(boolean value)
Sets whether to use binary mode.- Parameters:
value
- if true binary mode is used
-
getUseBinaryMode
public boolean getUseBinaryMode()
Returns whether binary mode is used.- Returns:
- true if binary mode is used
-
setClient
public void setClient(org.apache.commons.net.ftp.FTPClient value)
Sets the client to use.- Parameters:
value
- the client
-
getClient
public org.apache.commons.net.ftp.FTPClient getClient()
Returns the current session provider.- Returns:
- the client, null if none set
-
newClient
protected org.apache.commons.net.ftp.FTPClient newClient()
Returns a new client for the host defined in the options.- Returns:
- the client, null if failed to create
-
disconnect
protected void disconnect(org.apache.commons.net.ftp.FTPClient client)
Disconnects the SSH session, if necessary.- Parameters:
client
- the client to disconnect
-
isLocal
public boolean isLocal()
Returns whether the directory lister operates locally or remotely.- Specified by:
isLocal
in interfaceDirectoryLister
- Returns:
- true if local lister
-
hasParentDirectory
public boolean hasParentDirectory()
Returns whether the watch directory has a parent directory.- Specified by:
hasParentDirectory
in interfaceDirectoryLister
- Returns:
- true if parent directory available
-
newDirectory
public FtpFileObject newDirectory(String dir)
Returns a new directory relative to the watch directory.- Specified by:
newDirectory
in interfaceDirectoryLister
- Parameters:
dir
- the directory name- Returns:
- the new wrapper
-
newDirectory
public FtpFileObject newDirectory(String parent, String dir)
Returns a new directory generated from parent and sub-directory.- Specified by:
newDirectory
in interfaceDirectoryLister
- Parameters:
parent
- the parent directorydir
- the directory name- Returns:
- the new wrapper
-
search
protected void search(org.apache.commons.net.ftp.FTPClient client, String current, List<SortContainer> files, int depth) throws Exception
Performs the recursive search. Search goes deeper if != 0 (use -1 to start with for infinite search).- Parameters:
client
- the client to usecurrent
- the current directoryfiles
- the files collected so fardepth
- the depth indicator (searched no deeper, if 0)- Throws:
Exception
- if listing fails
-
search
public List<FtpFileObject> search(org.apache.commons.net.ftp.FTPClient client) throws Exception
Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.- Parameters:
client
- the FTP client to use- Returns:
- the list of absolute file/directory names
- Throws:
Exception
- if listing fails
-
list
public String[] list()
Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.- Specified by:
list
in interfaceDirectoryLister
- Returns:
- the list of absolute file/directory names
-
listObjects
public FtpFileObject[] listObjects()
Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.- Specified by:
listObjects
in interfaceDirectoryLister
- Returns:
- the list of file/directory wrappers
-
protocolCommandSent
public void protocolCommandSent(org.apache.commons.net.ProtocolCommandEvent event)
This method is invoked by a ProtocolCommandEvent source after sending a protocol command to a server.- Specified by:
protocolCommandSent
in interfaceorg.apache.commons.net.ProtocolCommandListener
- Parameters:
event
- The ProtocolCommandEvent fired.
-
protocolReplyReceived
public void protocolReplyReceived(org.apache.commons.net.ProtocolCommandEvent event)
This method is invoked by a ProtocolCommandEvent source after receiving a reply from a server.- Specified by:
protocolReplyReceived
in interfaceorg.apache.commons.net.ProtocolCommandListener
- Parameters:
event
- The ProtocolCommandEvent fired.
-
-