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.FTPClientm_Clientthe FTP client object.protected Stringm_Hostthe FTP host.protected BasePasswordm_Passwordthe FTP password to use.protected Stringm_RemoteDirthe directory to upload the file to.protected booleanm_UseBinaryModewhether to use binary file transfer mode.protected booleanm_UsePassiveModewhether to use passive mode.protected Stringm_Userthe 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 voidcleanUp()Cleans up data structures, frees up memory.protected Stringconnect()Starts up a FTP session.voiddefineOptions()Adds options to the internal list of options.protected voiddisconnect()Disconnects the FTP session, if necessary.protected StringdoSend(RemoteCommand cmd, RemoteCommandProcessor processor)Sends the command to the specified sscripting engine.protected StringdoSendRequest(RemoteCommand cmd, RemoteCommandProcessor processor)Sends the request command.protected StringdoSendResponse(RemoteCommand cmd, RemoteCommandProcessor processor)Sends the response command.protected org.apache.commons.net.ftp.FTPClientgetFTPClient()Returns the FTP client object.StringgetHost()Returns the host to connect to.BasePasswordgetPassword()Returns the FTP password to use.StringgetQuickInfo()Returns a quick info about the object, which can be displayed in the GUI.StringgetRemoteDir()Returns the remote directory.booleangetUseBinaryMode()Returns whether binary mode is used.booleangetUsePassiveMode()Returns whether passive mode is used.StringgetUser()Returns the FTP user name to use.StringglobalInfo()Returns a string describing the object.StringhostTipText()Returns the tip text for this property.StringpasswordTipText()Returns the tip text for this property.voidprotocolCommandSent(org.apache.commons.net.ProtocolCommandEvent event)This method is invoked by a ProtocolCommandEvent source after sending a protocol command to a server.voidprotocolReplyReceived(org.apache.commons.net.ProtocolCommandEvent event)This method is invoked by a ProtocolCommandEvent source after receiving a reply from a server.StringremoteDirTipText()Returns the tip text for this property.voidsetHost(String value)Sets the host to connect to.voidsetPassword(BasePassword value)Sets the FTP password to use.voidsetRemoteDir(String value)Sets the remote directory.voidsetUseBinaryMode(boolean value)Sets whether to use binary mode.voidsetUsePassiveMode(boolean value)Sets whether to use passive mode.voidsetUser(String value)Sets the FTP user to use.StringuseBinaryModeTipText()Returns the tip text for this property.StringusePassiveModeTipText()Returns the tip text for this property.StringuserTipText()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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin 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:
setPasswordin interfacePasswordSupporter- Parameters:
value- the password
-
getPassword
public BasePassword getPassword()
Returns the FTP password to use.- Specified by:
getPasswordin 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:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin 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:
doSendRequestin 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:
doSendResponsein 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:
protocolCommandSentin 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:
protocolReplyReceivedin interfaceorg.apache.commons.net.ProtocolCommandListener- Parameters:
event- The ProtocolCommandEvent fired.
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceCleanUpHandler- Overrides:
cleanUpin classAbstractConnection
-
-