cct.tools.filebrowser
Class SFTPBrowser

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by cct.tools.filebrowser.SFTPBrowser
All Implemented Interfaces:
FileBrowserInterface, java.awt.event.ActionListener, java.awt.event.MouseListener, java.util.EventListener, javax.swing.event.ListSelectionListener

public class SFTPBrowser
extends java.awt.event.MouseAdapter
implements FileBrowserInterface, java.awt.event.ActionListener, javax.swing.event.ListSelectionListener

Title: Computational Chemistry Tookit

Description:

It's a workhorse which performs all SFTP Browser functions

Copyright: Copyright (c) 2005-2007 Dr. Vladislav Vassiliev

Company: ANU


Nested Class Summary
(package private)  class SFTPBrowser.FileTranferWorker
           
 
Field Summary
(package private)  java.util.List authenticationMethods
           
(package private)  int AuthenticationResult
           
(package private)  boolean Busy
           
(package private)  java.lang.String[] columnNames
           
(package private)  java.util.List currentFileList
           
(package private)  java.lang.String currentPWD
           
(package private)  java.lang.Object[][] data
           
(package private)  boolean DEBUG
           
(package private) static java.lang.String DeleteItem
           
(package private)  java.util.HashMap directories
           
(package private) static java.lang.String DownloadItem
           
(package private)  javax.swing.JPopupMenu filePopup
           
(package private)  FilePropertiesDialog fileProps
           
(package private)  FileFilterImpl Filter
           
(package private)  javax.swing.JPopupMenu generalPopup
           
(package private) static java.lang.String GoToForlderItem
           
(package private)  java.lang.String hostName
           
(package private)  javax.swing.JFileChooser localFileChooser
           
(package private) static java.lang.String NewForlderItem
           
(package private)  java.text.NumberFormat numberFormat
           
(package private)  char[] password
           
(package private)  int portNumber
           
(package private) static java.lang.String PropertiesItem
           
(package private) static java.lang.String RefreshItem
           
(package private) static java.lang.String SelectAllItem
           
(package private)  SelectionInfoInterface selectionInfo
           
(package private)  com.sshtools.j2ssh.SftpClient sftpClient
           
(package private)  TableSorter sorter
           
(package private)  int[] sortStatus
           
(package private)  com.sshtools.j2ssh.SshClient ssh
           
(package private)  javax.swing.JTable table
           
(package private)  boolean tableInitiated
           
(package private)  int tableSelectionMode
           
(package private)  cct.tools.filebrowser.SFTPBrowser.FileBrowserTableModel tModel
           
(package private)  FileBrowserGUIInterface topGUI
           
(package private) static java.lang.String upDirectoryItem
           
(package private) static java.lang.String UploadDialogItem
           
(package private)  java.lang.String userName
           
 
Constructor Summary
SFTPBrowser()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          For processing popup menu items
 int authenticate(java.lang.String username, char[] pass)
          Authenticate the user on the remote host.
 void cd(java.lang.String dir)
          Changes the working directory on the remote server
 void connect(java.lang.String hostname)
          Connect the client to the server using default connection properties.
 void connect(java.lang.String hostname, java.lang.String username)
           
 void connect(java.lang.String hostname, java.lang.String username, char[] pass, int port)
          Connect the client to the server using default connection properties.
 void connectToHost(java.lang.String hostname, int port)
          Tries to connect to the host
 void disconnect()
           
 void downloadSelected()
          Downloads selected items
 void get(java.lang.String remote, java.lang.String local)
           
 void get(java.lang.String remote, java.lang.String local, com.sshtools.j2ssh.FileTransferProgress progress)
           
 java.util.List getAvailableAuthMethods(java.lang.String username)
          Returns the list of available authentication methods for a given user.
 java.awt.Component getComponent()
           
 int getFileCount()
           
 java.lang.String getFileName(java.lang.Object fileObject)
           
 java.lang.String[] getFileNames()
           
 java.lang.String getHost()
           
 char[] getPassword()
           
 int getPort()
           
 java.lang.String[] getSelectedFiles()
          Returns selected files (ignores selected directories, if any)
 java.lang.String[] getSelectedFolders()
          Returns selected directories (ignores selected files, if any)
 java.lang.String[] getSelectedItems()
          Returns absolute paths of all selected items
 com.sshtools.j2ssh.SftpClient getSftpClient()
           
 com.sshtools.j2ssh.SshClient getSshClient()
           
 java.lang.String getUsername()
           
 void goToFolderDialog()
           
 boolean isAuthenticated()
           
 void listUsingFilePattern(java.lang.String filePattern)
           
static void main(java.lang.String[] args)
           
 void mkdir()
           
 void mkdir(java.lang.String dir)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
(package private)  void openFilePropertiesDialog()
           
 void openUploadDialog()
          Opens upload dialog
 java.lang.String pwd()
           
 void reconnect()
          Tries to reconnect
 void refresh()
           
 void removeSelectedPaths()
          Removes selected file(s)/folder(s)
 void rm(java.lang.String path)
          Remove a file or directory from the remote computer
 void setFileFilter(FileFilterImpl filter)
           
 void setRemoteDirectory(java.lang.String directory)
          Changes the working directory on the remote server.
 void setSelectionInfoInterface(SelectionInfoInterface selection_info)
           
 void setSelectionMode(int mode)
          Sets selection mode: The following selectionMode values are allowed: ListSelectionModel.SINGLE_SELECTION Only one list index can be selected at a time.
 void setTopGUI(FileBrowserGUIInterface guiInterface)
           
 void upDirectory()
           
 void uploadFile(java.lang.String file)
          Upload a file to the remote computer.
 void valueChanged(javax.swing.event.ListSelectionEvent e)
           
 
Methods inherited from class java.awt.event.MouseAdapter
mouseEntered, mouseExited
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

upDirectoryItem

static final java.lang.String upDirectoryItem
See Also:
Constant Field Values

RefreshItem

static final java.lang.String RefreshItem
See Also:
Constant Field Values

NewForlderItem

static final java.lang.String NewForlderItem
See Also:
Constant Field Values

GoToForlderItem

static final java.lang.String GoToForlderItem
See Also:
Constant Field Values

DeleteItem

static final java.lang.String DeleteItem
See Also:
Constant Field Values

UploadDialogItem

static final java.lang.String UploadDialogItem
See Also:
Constant Field Values

SelectAllItem

static final java.lang.String SelectAllItem
See Also:
Constant Field Values

DownloadItem

static final java.lang.String DownloadItem
See Also:
Constant Field Values

PropertiesItem

static final java.lang.String PropertiesItem
See Also:
Constant Field Values

Filter

FileFilterImpl Filter

Busy

boolean Busy

tableInitiated

boolean tableInitiated

tableSelectionMode

int tableSelectionMode

topGUI

FileBrowserGUIInterface topGUI

selectionInfo

SelectionInfoInterface selectionInfo

directories

java.util.HashMap directories

table

javax.swing.JTable table

ssh

com.sshtools.j2ssh.SshClient ssh

hostName

java.lang.String hostName

userName

java.lang.String userName

password

char[] password

currentPWD

java.lang.String currentPWD

currentFileList

java.util.List currentFileList

authenticationMethods

java.util.List authenticationMethods

AuthenticationResult

int AuthenticationResult

portNumber

int portNumber

sftpClient

com.sshtools.j2ssh.SftpClient sftpClient

DEBUG

boolean DEBUG

columnNames

java.lang.String[] columnNames

sortStatus

int[] sortStatus

sorter

TableSorter sorter

data

java.lang.Object[][] data

numberFormat

java.text.NumberFormat numberFormat

generalPopup

javax.swing.JPopupMenu generalPopup

filePopup

javax.swing.JPopupMenu filePopup

tModel

cct.tools.filebrowser.SFTPBrowser.FileBrowserTableModel tModel

localFileChooser

javax.swing.JFileChooser localFileChooser

fileProps

FilePropertiesDialog fileProps
Constructor Detail

SFTPBrowser

public SFTPBrowser()
Method Detail

getFileCount

public int getFileCount()
Specified by:
getFileCount in interface FileBrowserInterface

getFileNames

public java.lang.String[] getFileNames()
Specified by:
getFileNames in interface FileBrowserInterface

setSelectionInfoInterface

public void setSelectionInfoInterface(SelectionInfoInterface selection_info)
Specified by:
setSelectionInfoInterface in interface FileBrowserInterface

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

listUsingFilePattern

public void listUsingFilePattern(java.lang.String filePattern)
                          throws java.lang.Exception
Specified by:
listUsingFilePattern in interface FileBrowserInterface
Throws:
java.lang.Exception

setFileFilter

public void setFileFilter(FileFilterImpl filter)
Specified by:
setFileFilter in interface FileBrowserInterface

getHost

public java.lang.String getHost()

getUsername

public java.lang.String getUsername()

getPassword

public char[] getPassword()

getPort

public int getPort()

get

public void get(java.lang.String remote,
                java.lang.String local)
         throws java.lang.Exception
Specified by:
get in interface FileBrowserInterface
Throws:
java.lang.Exception

get

public void get(java.lang.String remote,
                java.lang.String local,
                com.sshtools.j2ssh.FileTransferProgress progress)
         throws java.lang.Exception
Specified by:
get in interface FileBrowserInterface
Throws:
java.lang.Exception

pwd

public java.lang.String pwd()
Specified by:
pwd in interface FileBrowserInterface

getSftpClient

public com.sshtools.j2ssh.SftpClient getSftpClient()
                                            throws java.lang.Exception
Throws:
java.lang.Exception

getSshClient

public com.sshtools.j2ssh.SshClient getSshClient()

setSelectionMode

public void setSelectionMode(int mode)
                      throws java.lang.Exception
Sets selection mode: The following selectionMode values are allowed: ListSelectionModel.SINGLE_SELECTION Only one list index can be selected at a time. ListSelectionModel.SINGLE_INTERVAL_SELECTION One contiguous index interval can be selected at a time. ListSelectionModel.MULTIPLE_INTERVAL_SELECTION In this mode, there's no restriction on what can be selected. This is the default.

Specified by:
setSelectionMode in interface FileBrowserInterface
Parameters:
mode - int - an integer specifying the type of selections that are permissible
Throws:
java.lang.Exception

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
For processing popup menu items

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - ActionEvent

openFilePropertiesDialog

void openFilePropertiesDialog()

isAuthenticated

public boolean isAuthenticated()
Specified by:
isAuthenticated in interface FileBrowserInterface

downloadSelected

public void downloadSelected()
Downloads selected items

Specified by:
downloadSelected in interface FileBrowserInterface

getFileName

public java.lang.String getFileName(java.lang.Object fileObject)
                             throws java.lang.Exception
Throws:
java.lang.Exception

openUploadDialog

public void openUploadDialog()
Opens upload dialog


uploadFile

public void uploadFile(java.lang.String file)
                throws java.lang.Exception
Upload a file to the remote computer.

Parameters:
file - String - the path/name of the local file
Throws:
java.lang.Exception - - if an IO error occurs or the file does not exist

rm

public void rm(java.lang.String path)
Remove a file or directory from the remote computer

Specified by:
rm in interface FileBrowserInterface
Parameters:
path - String - the path of the remote file/directory

removeSelectedPaths

public void removeSelectedPaths()
Removes selected file(s)/folder(s)

Specified by:
removeSelectedPaths in interface FileBrowserInterface

goToFolderDialog

public void goToFolderDialog()

cd

public void cd(java.lang.String dir)
Changes the working directory on the remote server

Specified by:
cd in interface FileBrowserInterface
Parameters:
dir - String - the new working directory

mkdir

public void mkdir(java.lang.String dir)
Specified by:
mkdir in interface FileBrowserInterface

mkdir

public void mkdir()
Specified by:
mkdir in interface FileBrowserInterface

getComponent

public java.awt.Component getComponent()
Specified by:
getComponent in interface FileBrowserInterface

setTopGUI

public void setTopGUI(FileBrowserGUIInterface guiInterface)
Specified by:
setTopGUI in interface FileBrowserInterface

connectToHost

public void connectToHost(java.lang.String hostname,
                          int port)
                   throws java.lang.Exception
Tries to connect to the host

Parameters:
hostname - String
port - int
Throws:
java.lang.Exception

disconnect

public void disconnect()
Specified by:
disconnect in interface FileBrowserInterface

connect

public void connect(java.lang.String hostname)
             throws java.lang.Exception
Connect the client to the server using default connection properties. This call attempts to connect to the hostname specified on the standard SSH port of 22 and uses all the default connection properties.

Specified by:
connect in interface FileBrowserInterface
Parameters:
hostname - String - The hostname of the server to connect
Throws:
java.lang.Exception - - If an IO error occurs during the connect operation

connect

public void connect(java.lang.String hostname,
                    java.lang.String username)
             throws java.lang.Exception
Throws:
java.lang.Exception

reconnect

public void reconnect()
               throws java.lang.Exception
Tries to reconnect

Throws:
java.lang.Exception

connect

public void connect(java.lang.String hostname,
                    java.lang.String username,
                    char[] pass,
                    int port)
             throws java.lang.Exception
Connect the client to the server using default connection properties. This call attempts to connect to the hostname specified on the port of 22 and uses all the default connection properties.

Specified by:
connect in interface FileBrowserInterface
Parameters:
hostname - String
username - String
password - char[]
port - int
Throws:
java.lang.Exception

setRemoteDirectory

public void setRemoteDirectory(java.lang.String directory)
                        throws java.lang.Exception
Changes the working directory on the remote server.

Parameters:
directory - String - the new working directory
Throws:
java.lang.Exception

main

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

getAvailableAuthMethods

public java.util.List getAvailableAuthMethods(java.lang.String username)
                                       throws java.lang.Exception
Returns the list of available authentication methods for a given user.

Parameters:
username - String The name of the account for which you require the available authentication methods
Returns:
List - A list of Strings, for example "password", "publickey" & "keyboard-interactive"
Throws:
java.lang.Exception - If an IO error occurs during the operation

authenticate

public int authenticate(java.lang.String username,
                        char[] pass)
                 throws java.lang.Exception
Authenticate the user on the remote host.

Returns:
int - The authentication result
Throws:
java.lang.Exception

refresh

public void refresh()
Specified by:
refresh in interface FileBrowserInterface

upDirectory

public void upDirectory()
Specified by:
upDirectory in interface FileBrowserInterface

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class java.awt.event.MouseAdapter

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class java.awt.event.MouseAdapter

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Overrides:
mouseClicked in class java.awt.event.MouseAdapter

getSelectedItems

public java.lang.String[] getSelectedItems()
Returns absolute paths of all selected items

Returns:
String[]

getSelectedFiles

public java.lang.String[] getSelectedFiles()
Returns selected files (ignores selected directories, if any)

Specified by:
getSelectedFiles in interface FileBrowserInterface
Returns:
String[]

getSelectedFolders

public java.lang.String[] getSelectedFolders()
Returns selected directories (ignores selected files, if any)

Specified by:
getSelectedFolders in interface FileBrowserInterface
Returns:
String[]