Class ScriptEngine

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

public class ScriptEngine extends 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$
Author:
Bruce Blackshaw
  • Constructor Details

    • ScriptEngine

      public ScriptEngine() throws IOException
      Default constructor
      Throws:
      IOException
    • ScriptEngine

      public ScriptEngine(String user, String password) throws IOException
      Constructor. Allows user name and password to be passed in
      Parameters:
      user - username
      password - user's password
      Throws:
      IOException
  • Method Details

    • runCommand

      public CommandResult runCommand(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(String scriptPath)
      Execute the script in the supplied file
      Parameters:
      scriptPath - full path of the script file
      Returns:
      ScriptResult
      Throws:
      IOException
      FTPException
    • executeScript

      public ScriptResult executeScript(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:
      IOException
      FTPException
    • executeScript

      public ScriptResult executeScript(Reader scriptStream)
      Execute the script in the supplied stream
      Parameters:
      scriptStream - input stream containing the script file
      Returns:
      ScriptResult
      Throws:
      IOException
      FTPException
    • executeScript

      public ScriptResult executeScript(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:
      IOException
      FTPException
    • getCommandMap

      public Map getCommandMap()
      Get the map of commands
      Returns:
    • getVariablesMap

      public Map getVariablesMap()
      Get the map of variables
      Returns:
    • isEchoCommand

      public boolean isEchoCommand()
    • setEchoCommand

      public void setEchoCommand(boolean echoCommand)
    • getVariable

      public ScriptVariable getVariable(String name)
      Get a variable that has been set
      Parameters:
      name - name of variable
      Returns:
      ScriptVariable
    • setVariable

      public void setVariable(String name, String value)
      Set a variable
      Parameters:
      name - variable name
      value - variable value
    • getConfigFlags

      public String getConfigFlags()
      Get the config flags
      Returns:
      string
    • setConfigFlags

      public void setConfigFlags(String configFlags)
      Set the config flags
      Parameters:
      configFlags - config flags to set
    • getKnownHosts

      public String getKnownHosts()
      Get the known hosts path
      Returns:
      string
    • setKnownHosts

      public void setKnownHosts(String knownHosts)
      Set the known hosts path
      Parameters:
      knownHosts - path to known hosts file
    • getServerPublicKey

      public String getServerPublicKey()
      Get the server public key path
      Returns:
      path
    • setServerPublicKey

      public void setServerPublicKey(String serverPublicKey)
      Set the server public key path
      Parameters:
      serverPublicKey - path to public key
    • getClientPrivateKey

      public String getClientPrivateKey()
      Get the client private key path
      Returns:
      path
    • setClientPrivateKey

      public void setClientPrivateKey(String clientPrivateKey)
      Set the client private key path
      Parameters:
      clientPrivateKey - path to private key
    • getClientPrivateKeyPass

      public String getClientPrivateKeyPass()
      Get the passphrase for the client private key
      Returns:
      passphrase
    • setClientPrivateKeyPass

      public void setClientPrivateKeyPass(String clientPrivateKeyPass)
      Set the passphrase for the client private key
      Parameters:
      clientPrivateKeyPass - passphrase
    • startRecording

      public void startRecording(String file) throws IOException
      Start recording commands to file
      Parameters:
      recordFile - file to write commands to
      Throws:
      IOException
    • stopRecording

      public void stopRecording() throws IOException
      Stop recording commands
      Throws:
      IOException
    • isRecording

      public boolean isRecording()
      Is the engine currently recording commands?
      Returns:
      true if recording
    • getRecordFile

      public String getRecordFile()
      Get path of file used to record script to
      Returns:
      string
    • setRecordFile

      public void setRecordFile(String file)
      Set path of file to record script to
      Parameters:
      file - file path
    • writeToRecordFile

      public void writeToRecordFile(String msg) throws IOException
      Write a line to the script record file
      Parameters:
      msg - script line
      Throws:
      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 String getLocalDir()
      Get the local working directory
      Returns:
      local working directory
    • setLocalDir

      public void setLocalDir(String localDir)
      Set the local working directory
      Parameters:
      localDir - new local working directory
    • getAccountInfo

      public String getAccountInfo()
      Get the account info
      Returns:
      account info
    • setAccountInfo

      public void setAccountInfo(String accountInfo)
      Set the account info
      Parameters:
      accountInfo - account info
    • getParser

      public String getParser()
      Get the directory listing parser
      Returns:
      parser
    • setParser

      public void setParser(String parser)
      Set the directory listing parser
      Parameters:
      parser - directory listing parser
    • 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 String getLogFile()
      Get the name (or full path) of the log file
      Returns:
      log file name
    • setLogFile

      public void setLogFile(String logfile) throws IOException
      Set the name or path of the log file
      Parameters:
      logfile - logfile path or name
      Throws:
      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 String getPassword()
      Get the user's password
      Returns:
      password
    • setPassword

      public void setPassword(String password)
      Set the password to use
      Parameters:
      password - user's password
    • getMaxSSLVersion

      public int getMaxSSLVersion()
    • setMaxSSLVersion

      public void setMaxSSLVersion(int maxSSLVersion)
    • getClientCertificate

      public String getClientCertificate()
      Get the path of the client certificate for FTPS
      Returns:
      file path
    • setClientCertificate

      public void setClientCertificate(String clientCertificate)
      Set the path of the client certificate for FTPS
      Parameters:
      clientCertificate - file path
    • getClientPassphrase

      public String getClientPassphrase()
      Get the passphrase used for the client certificate
      Returns:
      string
    • setClientPassphrase

      public void setClientPassphrase(String clientPassphrase)
      Set the passphrase used for the client certificate
      Parameters:
      clientPassphrase -
    • getServerCertificate

      public String getServerCertificate()
      Get the path of the server certificate for FTPS, or the root certificate
      Returns:
      file path
    • setServerCertificate

      public void setServerCertificate(String serverCertificate)
      Set the path of the server certificate for FTPS, or the root certificate
      Parameters:
      serverCertificate - file path
    • getCommonName

      public 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(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
    • getProxySettings

      public ProxySettings getProxySettings()
      Get the proxy settings to be used
      Returns:
      proxy settings
    • getRemoteHost

      public String getRemoteHost()
      Get the remote host name
      Returns:
      hostname
    • setRemoteHost

      public void setRemoteHost(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 String getUser()
      Get the user
      Returns:
      username
    • setUser

      public void setUser(String user)
      Set the user
      Parameters:
      user - user name
    • main

      public static void main(String[] args)