com.enterprisedt.net.ftp.script
Class ScriptEngine

java.lang.Object
  extended by com.enterprisedt.net.ftp.script.ScriptEngine

public class ScriptEngine
extends java.lang.Object

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: 1.21 $
Author:
Bruce Blackshaw

Constructor Summary
ScriptEngine()
          Default constructor
ScriptEngine(java.lang.String user, java.lang.String password)
          Constructor.
 
Method Summary
 boolean canConnect()
          Can we connect with the current state?
 ScriptResult executeScript(java.io.Reader scriptStream)
          Execute the script in the supplied stream
 ScriptResult executeScript(java.io.Reader scriptStream, boolean exitAtEnd)
          Execute the script in the supplied stream.
 ScriptResult executeScript(java.lang.String scriptPath)
          Execute the script in the supplied file
 ScriptResult executeScript(java.lang.String scriptPath, boolean exitAtEnd)
          Execute the script in the supplied file
 int getActiveHighPort()
          Get the high port for active mode
 int getActiveLowPort()
          Get the low port for active mode
 java.lang.String getClientCertificate()
          Get the path of the client certificate for FTPS
 java.lang.String getClientPassphrase()
          Get the passphrase used for the client certificate
 java.util.Map getCommandMap()
          Get the map of commands
 java.lang.String getCommonName()
          Get the set common name for the server.
 FTPConnectMode getConnectMode()
          Get the connect mode.
 ProFTPClientInterface getFtp()
          Get a reference to the client being used
 boolean getIgnoreCommonName()
          Get the setting for ignoring the common name in server certificate validation.
 java.lang.String getKnownHosts()
          Get the known hosts path
 java.lang.String getLocalDir()
          Get the local working directory
 java.lang.String getLogFile()
          Get the name (or full path) of the log file
 Level getLogLevel()
          Get the log level
 CommandCollector getMessageCollector()
          Get the message listener
 java.lang.String getPassword()
          Get the user's password
 int getPort()
          Get the port number being used.
 Protocol getProtocol()
          Get the protocol to be used
 java.lang.String getRecordFile()
          Get path of file used to record script to
 java.lang.String getRemoteHost()
          Get the remote host name
 java.lang.String getServerCertificate()
          Get the path of the server certificate for FTPS, or the root certificate
 int getTimeout()
          Get the timeout value in seconds.
 java.lang.String getUser()
          Get the user
 ScriptVariable getVariable(java.lang.String name)
          Get a variable that has been set
 java.util.Map getVariablesMap()
          Get the map of variables
 boolean isDebug()
          Is debug turned on? Prints out each line before execution if on.
 boolean isEchoCommand()
           
 boolean isRecording()
          Is the engine currently recording commands?
static void main(java.lang.String[] args)
           
 void quit()
          Quit the session
 CommandResult runCommand(java.lang.String command)
          Run a command and write the output
 void setActivePortRange(int low, int high)
          Set the active mode port range to be used
 void setClientCertificate(java.lang.String clientCertificate)
          Set the path of the client certificate for FTPS
 void setClientPassphrase(java.lang.String clientPassphrase)
          Set the passphrase used for the client certificate
 void setCommonName(java.lang.String commonName)
          Set the common name for the server.
 void setConnectMode(FTPConnectMode mode)
          Set the connect mode.
 void setDebug(boolean debug)
          Set debug flag on or off
 void setEchoCommand(boolean echoCommand)
           
 void setFtp(ProFTPClientInterface ftp)
          Set the client reference
 void setIgnoreCommonName(boolean ignoreCommonName)
          Set whether the common name should be ignored in server certificate validation.
 void setKnownHosts(java.lang.String knownHosts)
          Set the known hosts path
 void setLocalDir(java.lang.String localDir)
          Set the local working directory
 void setLogFile(java.lang.String logfile)
          Set the name or path of the log file
 void setLogLevel(Level logLevel)
          Set the log level
 void setPassword(java.lang.String password)
          Set the password to use
 void setPort(int port)
          Set the port to connect to
 void setProtocol(Protocol protocol)
          Set the protocol to be used
 void setRecordFile(java.lang.String file)
          Set path of file to record script to
 void setRemoteHost(java.lang.String remoteHost)
          Set the remote host to connect to
 void setServerCertificate(java.lang.String serverCertificate)
          Set the path of the server certificate for FTPS, or the root certificate
 void setTimeout(int timeout)
          Set the timeout (in seconds).
 void setUser(java.lang.String user)
          Set the user
 void setVariable(java.lang.String name, java.lang.String value)
          Set a variable
 void startRecording(java.lang.String file)
          Start recording commands to file
 void stopRecording()
          Stop recording commands
 void writeToRecordFile(java.lang.String msg)
          Write a line to the script record file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptEngine

public ScriptEngine()
             throws java.io.IOException
Default constructor

Throws:
java.io.IOException

ScriptEngine

public ScriptEngine(java.lang.String user,
                    java.lang.String password)
             throws java.io.IOException
Constructor. Allows user name and password to be passed in

Parameters:
user - username
password - user's password
Throws:
java.io.IOException
Method Detail

runCommand

public CommandResult runCommand(java.lang.String command)
Run a command and write the output

Parameters:
command - command string including arguments
out - output stream for feedback
Returns:

quit

public void quit()
Quit the session

Parameters:
out - output stream for feedback

executeScript

public ScriptResult executeScript(java.lang.String scriptPath)
Execute the script in the supplied file

Parameters:
scriptPath - full path of the script file
Returns:
ScriptResult
Throws:
java.io.IOException
FTPException

executeScript

public ScriptResult executeScript(java.lang.String scriptPath,
                                  boolean exitAtEnd)
Execute the script in the supplied file

Parameters:
scriptPath - full path of the script file
exitAtEnd - if true, close connection at end
Returns:
ScriptResult
Throws:
java.io.IOException
FTPException

executeScript

public ScriptResult executeScript(java.io.Reader scriptStream)
Execute the script in the supplied stream

Parameters:
scriptStream - input stream containing the script file
Returns:
ScriptResult
Throws:
java.io.IOException
FTPException

executeScript

public ScriptResult executeScript(java.io.Reader scriptStream,
                                  boolean exitAtEnd)
Execute the script in the supplied stream.

Parameters:
scriptStream - input stream containing the script file
exitAtEnd - if true, close connection at end
Returns:
ScriptResult
Throws:
java.io.IOException
FTPException

getCommandMap

public java.util.Map getCommandMap()
Get the map of commands

Returns:

getVariablesMap

public java.util.Map getVariablesMap()
Get the map of variables

Returns:

isEchoCommand

public boolean isEchoCommand()

setEchoCommand

public void setEchoCommand(boolean echoCommand)

getVariable

public ScriptVariable getVariable(java.lang.String name)
Get a variable that has been set

Parameters:
name - name of variable
Returns:
ScriptVariable

setVariable

public void setVariable(java.lang.String name,
                        java.lang.String value)
Set a variable

Parameters:
name - variable name
value - variable value

getKnownHosts

public java.lang.String getKnownHosts()
Get the known hosts path

Returns:
string

setKnownHosts

public void setKnownHosts(java.lang.String knownHosts)
Set the known hosts path

Parameters:
knownHosts - path to known hosts file

startRecording

public void startRecording(java.lang.String file)
                    throws java.io.IOException
Start recording commands to file

Parameters:
recordFile - file to write commands to
Throws:
java.io.IOException

stopRecording

public void stopRecording()
                   throws java.io.IOException
Stop recording commands

Throws:
java.io.IOException

isRecording

public boolean isRecording()
Is the engine currently recording commands?

Returns:
true if recording

getRecordFile

public java.lang.String getRecordFile()
Get path of file used to record script to

Returns:
string

setRecordFile

public void setRecordFile(java.lang.String file)
Set path of file to record script to

Parameters:
file - file path

writeToRecordFile

public void writeToRecordFile(java.lang.String msg)
                       throws java.io.IOException
Write a line to the script record file

Parameters:
msg - script line
Throws:
java.io.IOException

getConnectMode

public FTPConnectMode getConnectMode()
Get the connect mode. PASV by default.

Returns:
connect mode

setConnectMode

public void setConnectMode(FTPConnectMode mode)
Set the connect mode.

Parameters:
mode - mode to set.

getLocalDir

public java.lang.String getLocalDir()
Get the local working directory

Returns:
local working directory

setLocalDir

public void setLocalDir(java.lang.String localDir)
Set the local working directory

Parameters:
localDir - new local working directory

getMessageCollector

public CommandCollector 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

public ProFTPClientInterface getFtp()
Get a reference to the client being used

Returns:
client reference

setFtp

public void setFtp(ProFTPClientInterface ftp)
Set the client reference

Parameters:
ftp - client reference

getLogFile

public java.lang.String getLogFile()
Get the name (or full path) of the log file

Returns:
log file name

setLogFile

public void setLogFile(java.lang.String logfile)
                throws java.io.IOException
Set the name or path of the log file

Parameters:
logfile - logfile path or name
Throws:
java.io.IOException

getLogLevel

public Level getLogLevel()
Get the log level

Returns:
log level

setLogLevel

public void setLogLevel(Level logLevel)
Set the log level

Parameters:
logLevel - new log level

getPassword

public java.lang.String getPassword()
Get the user's password

Returns:
password

setPassword

public void setPassword(java.lang.String password)
Set the password to use

Parameters:
password - user's password

getClientCertificate

public java.lang.String getClientCertificate()
Get the path of the client certificate for FTPS

Returns:
file path

setClientCertificate

public void setClientCertificate(java.lang.String clientCertificate)
Set the path of the client certificate for FTPS

Parameters:
clientCertificate - file path

getClientPassphrase

public java.lang.String getClientPassphrase()
Get the passphrase used for the client certificate

Returns:
string

setClientPassphrase

public void setClientPassphrase(java.lang.String clientPassphrase)
Set the passphrase used for the client certificate

Parameters:
clientPassphrase -

getServerCertificate

public java.lang.String getServerCertificate()
Get the path of the server certificate for FTPS, or the root certificate

Returns:
file path

setServerCertificate

public void setServerCertificate(java.lang.String serverCertificate)
Set the path of the server certificate for FTPS, or the root certificate

Parameters:
serverCertificate - file path

getCommonName

public java.lang.String 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

public void setCommonName(java.lang.String commonName)
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 port
high - 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

public Protocol getProtocol()
Get the protocol to be used

Returns:
protocol

setProtocol

public void setProtocol(Protocol protocol)
Set the protocol to be used

Parameters:
protocol - protocol to use

getRemoteHost

public java.lang.String getRemoteHost()
Get the remote host name

Returns:
hostname

setRemoteHost

public void setRemoteHost(java.lang.String remoteHost)
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

public java.lang.String getUser()
Get the user

Returns:
username

setUser

public void setUser(java.lang.String user)
Set the user

Parameters:
user - user name

main

public static void main(java.lang.String[] args)


Copyright © 2001-2006 Enterprise Distributed Technologies Ltd. All Rights Reserved.