examples
Class BasicClient

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by examples.BasicClient
All Implemented Interfaces:
SSH2Interactor, TerminalMenuListener, java.awt.event.WindowFocusListener, java.awt.event.WindowListener, java.awt.event.WindowStateListener, java.lang.Runnable, java.util.EventListener

public final class BasicClient
extends java.awt.event.WindowAdapter
implements SSH2Interactor, TerminalMenuListener, java.lang.Runnable

Ssh2 client which opens a terminal window and asks the user where to connect to.

Usage: java -cp examples.jar examples.BasicClient [props_file_name]

Username and password as well as server can be stored in the properties file.

It can also read portforwards from properties. Create properties named 'localN' or 'remoteN' where N is an integer 0-31. The contents of the properties is in the following format:

   [/plugin/][local_host:]local_port:remote_host:remote_port
 
This client understands the ftp and sniff plugins.

See Also:
SSH2FTPProxyFilter, SSH2StreamSniffer

Constructor Summary
BasicClient(java.util.Properties props)
          Simple constructor where all required properties have good default values so no properties have to be provided.
 
Method Summary
 void close(TerminalMenuHandler origMenu)
          Called when the user has selected close in the menu
 void doClose()
          Close the connection to the server (if any) in a controlled way.
 int getExitStatus()
          Get the exit status from the SSH2ConsoleRemote instance
static void main(java.lang.String[] argv)
          Run the application
 java.lang.String promptLine(java.lang.String prompt, boolean echo)
          Prompt for a single string.
 int promptList(java.lang.String name, java.lang.String instruction, java.lang.String[] choices)
          This function is only used by AppGate internal code so there is no need to actually implement it in any other code.
 java.lang.String[] promptMulti(java.lang.String[] prompts, boolean[] echos)
          Prompt for multiple strings.
 java.lang.String[] promptMultiFull(java.lang.String name, java.lang.String instruction, java.lang.String[] prompts, boolean[] echos)
          Prompt for multiple strings.
 void run()
          Actually runs the client.
 void update()
          Called when the menu is updated
 void windowClosing(java.awt.event.WindowEvent e)
          Overide corresponding function in java.awt.event.WindowAdapter
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicClient

public BasicClient(java.util.Properties props)
Simple constructor where all required properties have good default values so no properties have to be provided. However the properties is the only way to change the encryption algorithms etc in this client.

Parameters:
props - SSH2 protocol properties.
Method Detail

run

public void run()
Actually runs the client. This gets called from the main function.

Specified by:
run in interface java.lang.Runnable

getExitStatus

public int getExitStatus()
Get the exit status from the SSH2ConsoleRemote instance

Returns:
the exit status

doClose

public void doClose()
Close the connection to the server (if any) in a controlled way.


windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Overide corresponding function in java.awt.event.WindowAdapter

Specified by:
windowClosing in interface java.awt.event.WindowListener
Overrides:
windowClosing in class java.awt.event.WindowAdapter

close

public void close(TerminalMenuHandler origMenu)
Description copied from interface: TerminalMenuListener
Called when the user has selected close in the menu

Specified by:
close in interface TerminalMenuListener
Parameters:
origMenu - the menu where close was selected

update

public void update()
Description copied from interface: TerminalMenuListener
Called when the menu is updated

Specified by:
update in interface TerminalMenuListener

main

public static void main(java.lang.String[] argv)
Run the application


promptLine

public java.lang.String promptLine(java.lang.String prompt,
                                   boolean echo)
                            throws SSH2UserCancelException
Description copied from interface: SSH2Interactor
Prompt for a single string.

Specified by:
promptLine in interface SSH2Interactor
Parameters:
prompt - The prompt string to show
echo - True if the text the user enters should be echoed.
Returns:
The text entered by the user.
Throws:
SSH2UserCancelException

promptMulti

public java.lang.String[] promptMulti(java.lang.String[] prompts,
                                      boolean[] echos)
                               throws SSH2UserCancelException
Description copied from interface: SSH2Interactor
Prompt for multiple strings. The expectation here is that the client will put up a dialog where the user sees multiple prompts and input fields.

Specified by:
promptMulti in interface SSH2Interactor
Parameters:
prompts - List of prompts to show
echos - List of boolean values which indicates if the text entered for the corresponding prompt should be echoed.
Returns:
An array of strings which contains on element for each prompt, in the same order. The elements should contain the text the user entered.
Throws:
SSH2UserCancelException

promptMultiFull

public java.lang.String[] promptMultiFull(java.lang.String name,
                                          java.lang.String instruction,
                                          java.lang.String[] prompts,
                                          boolean[] echos)
                                   throws SSH2UserCancelException
Description copied from interface: SSH2Interactor
Prompt for multiple strings. The expectation here is that the client will put up a dialog where the user sees multiple prompts and input fields. This version of the call includes more elements which should be shown in the dialog.

Specified by:
promptMultiFull in interface SSH2Interactor
Parameters:
name - Suggested title of the dialog
instruction - Instructions to show to user in the dialog
prompts - List of prompts to show
echos - List of boolean values which indicates if the text entered for the corresponding prompt should be echoed.
Returns:
An array of strings which contains on element for each prompt, in the same order. The elements should contain the text the user entered.
Throws:
SSH2UserCancelException

promptList

public int promptList(java.lang.String name,
                      java.lang.String instruction,
                      java.lang.String[] choices)
               throws SSH2UserCancelException
Description copied from interface: SSH2Interactor
This function is only used by AppGate internal code so there is no need to actually implement it in any other code.

It is used to let the user select one element in a list.

Specified by:
promptList in interface SSH2Interactor
Parameters:
name - Suggested title of dialog
instruction - Instructions to show to user
choices - Array of possible choices
Returns:
index of selected list item
Throws:
SSH2UserCancelException