Package com.enterprisedt.net.ftp.script
Class ScriptEngine
java.lang.Object
com.enterprisedt.net.ftp.script.ScriptEngine
Scripting engine, used to load FTP scripts and execute them.
Generally, the only methods used should be the constructor and
the executeScript() methods.
The setter methods should be used with caution. Typically, when
the script is run these setter methods are called to set various
properties. This means any properties manually set with these
methods will be overwritten.
- Version:
- $Revision$
- Author:
- Bruce Blackshaw
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCan we connect with the current state?executeScript(Reader scriptStream) Execute the script in the supplied streamexecuteScript(Reader scriptStream, boolean exitAtEnd) Execute the script in the supplied stream.executeScript(String scriptPath) Execute the script in the supplied fileexecuteScript(String scriptPath, boolean exitAtEnd) Execute the script in the supplied fileGet the account infointGet the high port for active modeintGet the low port for active modeGet the path of the client certificate for FTPSGet the passphrase used for the client certificateGet the client private key pathGet the passphrase for the client private keyGet the map of commandsGet the set common name for the server.Get the config flagsGet the connect mode.getFtp()Get a reference to the client being usedbooleanGet the setting for ignoring the common name in server certificate validation.Get the known hosts pathGet the local working directoryGet the name (or full path) of the log fileGet the log levelintGet the message listenerGet the directory listing parserGet the user's passwordintgetPort()Get the port number being used.Get the protocol to be usedGet the proxy settings to be usedGet path of file used to record script toGet the remote host nameGet the path of the server certificate for FTPS, or the root certificateGet the server public key pathintGet the timeout value in seconds.getUser()Get the usergetVariable(String name) Get a variable that has been setGet the map of variablesbooleanisDebug()Is debug turned on? Prints out each line before execution if on.booleanbooleanIs the engine currently recording commands?static voidvoidquit()Quit the sessionrunCommand(String command) Run a command and write the outputvoidsetAccountInfo(String accountInfo) Set the account infovoidsetActivePortRange(int low, int high) Set the active mode port range to be usedvoidsetClientCertificate(String clientCertificate) Set the path of the client certificate for FTPSvoidsetClientPassphrase(String clientPassphrase) Set the passphrase used for the client certificatevoidsetClientPrivateKey(String clientPrivateKey) Set the client private key pathvoidsetClientPrivateKeyPass(String clientPrivateKeyPass) Set the passphrase for the client private keyvoidsetCommonName(String commonName) Set the common name for the server.voidsetConfigFlags(String configFlags) Set the config flagsvoidsetConnectMode(FTPConnectMode mode) Set the connect mode.voidsetDebug(boolean debug) Set debug flag on or offvoidsetEchoCommand(boolean echoCommand) voidSet the client referencevoidsetIgnoreCommonName(boolean ignoreCommonName) Set whether the common name should be ignored in server certificate validation.voidsetKnownHosts(String knownHosts) Set the known hosts pathvoidsetLocalDir(String localDir) Set the local working directoryvoidsetLogFile(String logfile) Set the name or path of the log filevoidsetLogLevel(Level logLevel) Set the log levelvoidsetMaxSSLVersion(int maxSSLVersion) voidSet the directory listing parservoidsetPassword(String password) Set the password to usevoidsetPort(int port) Set the port to connect tovoidsetProtocol(Protocol protocol) Set the protocol to be usedvoidsetRecordFile(String file) Set path of file to record script tovoidsetRemoteHost(String remoteHost) Set the remote host to connect tovoidsetServerCertificate(String serverCertificate) Set the path of the server certificate for FTPS, or the root certificatevoidsetServerPublicKey(String serverPublicKey) Set the server public key pathvoidsetTimeout(int timeout) Set the timeout (in seconds).voidSet the uservoidsetVariable(String name, String value) Set a variablevoidstartRecording(String file) Start recording commands to filevoidStop recording commandsvoidwriteToRecordFile(String msg) Write a line to the script record file
-
Constructor Details
-
ScriptEngine
Default constructor- Throws:
IOException
-
ScriptEngine
Constructor. Allows user name and password to be passed in- Parameters:
user- usernamepassword- user's password- Throws:
IOException
-
-
Method Details
-
runCommand
Run a command and write the output- Parameters:
command- command string including argumentsout- output stream for feedback- Returns:
-
quit
public void quit()Quit the session- Parameters:
out- output stream for feedback
-
executeScript
Execute the script in the supplied file- Parameters:
scriptPath- full path of the script file- Returns:
- ScriptResult
- Throws:
IOExceptionFTPException
-
executeScript
Execute the script in the supplied file- Parameters:
scriptPath- full path of the script fileexitAtEnd- if true, close connection at end- Returns:
- ScriptResult
- Throws:
IOExceptionFTPException
-
executeScript
Execute the script in the supplied stream- Parameters:
scriptStream- input stream containing the script file- Returns:
- ScriptResult
- Throws:
IOExceptionFTPException
-
executeScript
Execute the script in the supplied stream.- Parameters:
scriptStream- input stream containing the script fileexitAtEnd- if true, close connection at end- Returns:
- ScriptResult
- Throws:
IOExceptionFTPException
-
getCommandMap
Get the map of commands- Returns:
-
getVariablesMap
Get the map of variables- Returns:
-
isEchoCommand
public boolean isEchoCommand() -
setEchoCommand
public void setEchoCommand(boolean echoCommand) -
getVariable
Get a variable that has been set- Parameters:
name- name of variable- Returns:
- ScriptVariable
-
setVariable
Set a variable- Parameters:
name- variable namevalue- variable value
-
getConfigFlags
Get the config flags- Returns:
- string
-
setConfigFlags
Set the config flags- Parameters:
configFlags- config flags to set
-
getKnownHosts
Get the known hosts path- Returns:
- string
-
setKnownHosts
Set the known hosts path- Parameters:
knownHosts- path to known hosts file
-
getServerPublicKey
Get the server public key path- Returns:
- path
-
setServerPublicKey
Set the server public key path- Parameters:
serverPublicKey- path to public key
-
getClientPrivateKey
Get the client private key path- Returns:
- path
-
setClientPrivateKey
Set the client private key path- Parameters:
clientPrivateKey- path to private key
-
getClientPrivateKeyPass
Get the passphrase for the client private key- Returns:
- passphrase
-
setClientPrivateKeyPass
Set the passphrase for the client private key- Parameters:
clientPrivateKeyPass- passphrase
-
startRecording
Start recording commands to file- Parameters:
recordFile- file to write commands to- Throws:
IOException
-
stopRecording
Stop recording commands- Throws:
IOException
-
isRecording
public boolean isRecording()Is the engine currently recording commands?- Returns:
- true if recording
-
getRecordFile
Get path of file used to record script to- Returns:
- string
-
setRecordFile
Set path of file to record script to- Parameters:
file- file path
-
writeToRecordFile
Write a line to the script record file- Parameters:
msg- script line- Throws:
IOException
-
getConnectMode
Get the connect mode. PASV by default.- Returns:
- connect mode
-
setConnectMode
Set the connect mode.- Parameters:
mode- mode to set.
-
getLocalDir
Get the local working directory- Returns:
- local working directory
-
setLocalDir
Set the local working directory- Parameters:
localDir- new local working directory
-
getAccountInfo
Get the account info- Returns:
- account info
-
setAccountInfo
Set the account info- Parameters:
accountInfo- account info
-
getParser
Get the directory listing parser- Returns:
- parser
-
setParser
Set the directory listing parser- Parameters:
parser- directory listing parser
-
getMessageCollector
Get the message listener- Returns:
- message listener
-
isDebug
public boolean isDebug()Is debug turned on? Prints out each line before execution if on.- Returns:
- true if debug enabled, false otherwise
-
setDebug
public void setDebug(boolean debug) Set debug flag on or off- Parameters:
debug- enable or disable debug
-
getFtp
Get a reference to the client being used- Returns:
- client reference
-
setFtp
Set the client reference- Parameters:
ftp- client reference
-
getLogFile
Get the name (or full path) of the log file- Returns:
- log file name
-
setLogFile
Set the name or path of the log file- Parameters:
logfile- logfile path or name- Throws:
IOException
-
getLogLevel
Get the log level- Returns:
- log level
-
setLogLevel
Set the log level- Parameters:
logLevel- new log level
-
getPassword
Get the user's password- Returns:
- password
-
setPassword
Set the password to use- Parameters:
password- user's password
-
getMaxSSLVersion
public int getMaxSSLVersion() -
setMaxSSLVersion
public void setMaxSSLVersion(int maxSSLVersion) -
getClientCertificate
Get the path of the client certificate for FTPS- Returns:
- file path
-
setClientCertificate
Set the path of the client certificate for FTPS- Parameters:
clientCertificate- file path
-
getClientPassphrase
Get the passphrase used for the client certificate- Returns:
- string
-
setClientPassphrase
Set the passphrase used for the client certificate- Parameters:
clientPassphrase-
-
getServerCertificate
Get the path of the server certificate for FTPS, or the root certificate- Returns:
- file path
-
setServerCertificate
Set the path of the server certificate for FTPS, or the root certificate- Parameters:
serverCertificate- file path
-
getCommonName
Get the set common name for the server. This is what is used to match against the server certificate if the hostname is not to be used.- Returns:
- common name
-
setCommonName
Set the common name for the server. This is what is used to match against the server certificate if the hostname is not to be used.- Parameters:
common- name string
-
getIgnoreCommonName
public boolean getIgnoreCommonName()Get the setting for ignoring the common name in server certificate validation. This is only used if a server certificate is set. If set to true, the common name in the server certificate is not matched with the hostname of the server (or any set common names). The default is false.- Returns:
- true to skip common name matching in server validation
-
setIgnoreCommonName
public void setIgnoreCommonName(boolean ignoreCommonName) Set whether the common name should be ignored in server certificate validation. This is only used if a server certificate is set. If set to true, the common name in the server certificate is not matched with the hostname of the server (or any set common names). The default is false.- Parameters:
ignoreCommonName-
-
getPort
public int getPort()Get the port number being used. The default is 0, which means the port will be set internally depending on the protocol used.- Returns:
- port number
-
setPort
public void setPort(int port) Set the port to connect to- Parameters:
port- port used
-
setActivePortRange
public void setActivePortRange(int low, int high) Set the active mode port range to be used- Parameters:
low- low porthigh- high port
-
getActiveLowPort
public int getActiveLowPort()Get the low port for active mode- Returns:
- low port
-
getActiveHighPort
public int getActiveHighPort()Get the high port for active mode- Returns:
- high port
-
getProtocol
Get the protocol to be used- Returns:
- protocol
-
setProtocol
Set the protocol to be used- Parameters:
protocol- protocol to use
-
getProxySettings
Get the proxy settings to be used- Returns:
- proxy settings
-
getRemoteHost
Get the remote host name- Returns:
- hostname
-
setRemoteHost
Set the remote host to connect to- Parameters:
remoteHost- remote host name
-
canConnect
public boolean canConnect()Can we connect with the current state?- Returns:
- true if can connect, false otherwise
-
getTimeout
public int getTimeout()Get the timeout value in seconds. The default is 0, which is an infinite timeout.- Returns:
- timeout
-
setTimeout
public void setTimeout(int timeout) Set the timeout (in seconds).- Parameters:
timeout- timeout value in seconds
-
getUser
Get the user- Returns:
- username
-
setUser
Set the user- Parameters:
user- user name
-
main
-