Package adams.scripting.connection
Class FTPConnection
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.scripting.connection.AbstractConnection
-
- adams.scripting.connection.FTPConnection
-
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,PasswordSupporter
,QuickInfoSupporter
,SizeOfHandler
,Connection
,Serializable
,Comparable<Connection>
,EventListener
,org.apache.commons.net.ProtocolCommandListener
public class FTPConnection extends AbstractConnection implements org.apache.commons.net.ProtocolCommandListener, PasswordSupporter
Uses FTP to send commands.- 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 client object.protected String
m_Host
the FTP host.protected BasePassword
m_Password
the FTP password to use.protected String
m_RemoteDir
the directory to upload the file to.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.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description FTPConnection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanUp()
Cleans up data structures, frees up memory.protected String
connect()
Starts up a FTP session.void
defineOptions()
Adds options to the internal list of options.protected void
disconnect()
Disconnects the FTP session, if necessary.protected String
doSend(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the command to the specified sscripting engine.protected String
doSendRequest(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the request command.protected String
doSendResponse(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the response command.protected org.apache.commons.net.ftp.FTPClient
getFTPClient()
Returns the FTP client object.String
getHost()
Returns the host to connect to.BasePassword
getPassword()
Returns the FTP password to use.String
getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.String
getRemoteDir()
Returns the remote directory.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.String
globalInfo()
Returns a string describing the object.String
hostTipText()
Returns the tip text for this property.String
passwordTipText()
Returns the tip text for this property.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.String
remoteDirTipText()
Returns the tip text for this property.void
setHost(String value)
Sets the host to connect to.void
setPassword(BasePassword value)
Sets the FTP password to use.void
setRemoteDir(String value)
Sets the remote directory.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.String
useBinaryModeTipText()
Returns the tip text for this property.String
usePassiveModeTipText()
Returns the tip text for this property.String
userTipText()
Returns the tip text for this property.-
Methods inherited from class adams.scripting.connection.AbstractConnection
checkRequest, checkResponse, compareTo, equals, sendRequest, sendResponse, toString
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
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_RemoteDir
protected String m_RemoteDir
the directory to upload the file to.
-
m_Client
protected org.apache.commons.net.ftp.FTPClient m_Client
the FTP client object.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
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
-
hostTipText
public String hostTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
userTipText
public String userTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
passwordTipText
public String passwordTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
usePassiveModeTipText
public String usePassiveModeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
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
-
useBinaryModeTipText
public String useBinaryModeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRemoteDir
public void setRemoteDir(String value)
Sets the remote directory.- Parameters:
value
- the remote directory
-
getRemoteDir
public String getRemoteDir()
Returns the remote directory.- Returns:
- the remote directory.
-
remoteDirTipText
public String remoteDirTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractConnection
- Returns:
- null if no info available, otherwise short string
-
connect
protected String connect()
Starts up a FTP session.- Returns:
- null if OK, otherwise error message
-
disconnect
protected void disconnect()
Disconnects the FTP session, if necessary.
-
getFTPClient
protected org.apache.commons.net.ftp.FTPClient getFTPClient()
Returns the FTP client object.- Returns:
- the FTP client, null if failed to connect
-
doSend
protected String doSend(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the command to the specified sscripting engine.- Parameters:
cmd
- the command to sendprocessor
- for formatting/parsing- Returns:
- null if successfully sent, otherwise error message
-
doSendRequest
protected String doSendRequest(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the request command.- Specified by:
doSendRequest
in classAbstractConnection
- Parameters:
cmd
- the command to sendprocessor
- the processor for formatting/parsing- Returns:
- null if successful, otherwise error message
-
doSendResponse
protected String doSendResponse(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the response command.- Specified by:
doSendResponse
in classAbstractConnection
- Parameters:
cmd
- the command to sendprocessor
- the processor for formatting/parsing- Returns:
- null if successful, otherwise error message
-
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.
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractConnection
-
-