com.bea.wli.sftp.spi
Interface SFtpClient

All Known Implementing Classes:
AbstractSFtpClient

public interface SFtpClient

This class represents the Sftp client. The user is expected to implement all the methods provided in this interface using third party SFTP client implementation.


Method Summary
 boolean acceptUnknownHostKeys()
          Returns whether to accept keys from unknown SFTP hosts
 void cd(String dir)
          Changes the working directory on the remote server
 void connect()
          Connects to the SSH server and authenticates the user using the pre-set authentication method
 void disconnect()
          Disconnects from the remote server and cleans up the resources
 void get(String remotePath, OutputStream outStream, SFtpFileTransferMode mode)
          Retrieves the file on the remote server and copies it to a stream
 InputStream get(String remotePath, SFtpFileTransferMode mode)
          Retrieves the file given the path as a stream
 void get(String remotePath, String localPath, SFtpFileTransferMode mode)
          Retrieves the file on the remote server and copies it on to the local file system
 SFtpAuthMethod getAuthenticationMethod()
          Retrieves the SFtp client authentication method
 HashMap<String,Object> getCustomProperties()
          Retrieves additional properties for connecting to SFTP server
 String getHostname()
          Returns the Host name of the SSH server
 int getPort()
          Return the port number of the SSH server
 SFtpVersion getSSHVersion()
          Retrieves the SSH version
 String getUserName()
          Returns the user name
 List<SFtpFile> list()
          Returns list of files available in the current working directory on the Remote server
 List<SFtpFile> list(String path)
          Returns a list of files available on the remote server given the path to the directory
 void mkdir(String dir)
           Creates a new directory on the remote server.
 void mkdirs(String dir)
           Create a directory or set of directories.
 void put(InputStream inStream, String remotePath, SFtpFileTransferMode mode)
          Copies the stream on to the remote server
 void put(String localPath, String remotePath, SFtpFileTransferMode mode)
          Copies the local file on to the remote server
 String pwd()
           Returns the absolute path name of the current remote working directory.
 void rename(String oldPath, String newPath)
          Renames the file given the old path and new path to the file
 void rm(String path)
          Removes the file given the path on the remote server
 void rmdir(String path)
          Removes the directory given the path on the remote server
 void setAcceptUnknownHostKeys(boolean accept)
          Sets whether to accept unknown host server keys or not
 void setAuthenticationMethod(SFtpAuthMethod authMethod)
          Sets the SFtp client authentication method
 void setCustomProperties(HashMap<String,Object> props)
          Sets the additional properties for connecting to SFTP server
 void setPassPhrase(char[] phrase)
          Sets the Pass phrase for the private key file
 void setPassword(char[] pwd)
          Sets the password used for authentication
 void setPrivateKeyFile(String path)
          Sets the Private key file for authentication
 void setSSHVersion(SFtpVersion sshVersion)
          Sets the SSH version
 void setUserName(String userName)
          Sets the user name for authentication
 

Method Detail

setAuthenticationMethod

void setAuthenticationMethod(SFtpAuthMethod authMethod)
Sets the SFtp client authentication method

Parameters:
authMethod - - auth method

getAuthenticationMethod

SFtpAuthMethod getAuthenticationMethod()
Retrieves the SFtp client authentication method

Returns:
Auth method

setAcceptUnknownHostKeys

void setAcceptUnknownHostKeys(boolean accept)
Sets whether to accept unknown host server keys or not

Parameters:
accept - - whether to accept unknown host keys

acceptUnknownHostKeys

boolean acceptUnknownHostKeys()
Returns whether to accept keys from unknown SFTP hosts

Returns:
whether to accept keys from unknown hosts or not

setSSHVersion

void setSSHVersion(SFtpVersion sshVersion)
Sets the SSH version

Parameters:
sshVersion - - SSH version

getSSHVersion

SFtpVersion getSSHVersion()
Retrieves the SSH version

Returns:
SSH version

connect

void connect()
             throws SFtpClientException
Connects to the SSH server and authenticates the user using the pre-set authentication method

Throws:
SFtpClientException - - if failed to connect to the server or failed to authenticate with the server

setUserName

void setUserName(String userName)
Sets the user name for authentication

Parameters:
userName - - name of the user

getUserName

String getUserName()
Returns the user name

Returns:
user name

getHostname

String getHostname()
Returns the Host name of the SSH server

Returns:
host name

getPort

int getPort()
Return the port number of the SSH server

Returns:
port number

setPassword

void setPassword(char[] pwd)
Sets the password used for authentication

Parameters:
pwd - - password

setPassPhrase

void setPassPhrase(char[] phrase)
Sets the Pass phrase for the private key file

Parameters:
phrase - - pass phrase

setPrivateKeyFile

void setPrivateKeyFile(String path)
Sets the Private key file for authentication

Parameters:
path - - path to the private key file

setCustomProperties

void setCustomProperties(HashMap<String,Object> props)
Sets the additional properties for connecting to SFTP server

Parameters:
props - - name value pairs

getCustomProperties

HashMap<String,Object> getCustomProperties()
Retrieves additional properties for connecting to SFTP server

Returns:
set of name/value pairs

pwd

String pwd()
           throws SFtpClientException

Returns the absolute path name of the current remote working directory.

Returns:
the absolute path of the remote working directory.
Throws:
SFtpClientException

cd

void cd(String dir)
        throws SFtpClientException
Changes the working directory on the remote server

Parameters:
dir - - path to the directory
Throws:
SFtpClientException

mkdir

void mkdir(String dir)
           throws SFtpClientException

Creates a new directory on the remote server. This method will throw an exception if the directory already exists. To create directories and disregard any errors use the mkdirs method.

Parameters:
dir - the name of the new directory
Throws:
SFtpClientException

mkdirs

void mkdirs(String dir)
            throws SFtpClientException

Create a directory or set of directories. This method will not fail even if the directories exist. It is advisable to test whether the directory exists before attempting an operation by using the stat method to return the directories attributes.

Parameters:
dir - the path of directories to create.
Throws:
SFtpClientException

rm

void rm(String path)
        throws SFtpClientException
Removes the file given the path on the remote server

Parameters:
path - - path to the file to be removed
Throws:
SFtpClientException

rmdir

void rmdir(String path)
           throws SFtpClientException
Removes the directory given the path on the remote server

Parameters:
path - - path to the directory
Throws:
SFtpClientException

rename

void rename(String oldPath,
            String newPath)
            throws SFtpClientException
Renames the file given the old path and new path to the file

Parameters:
oldPath - - path to the file to be renamed
newPath - - path to the new file name
Throws:
SFtpClientException

list

List<SFtpFile> list(String path)
                    throws SFtpClientException
Returns a list of files available on the remote server given the path to the directory

Parameters:
path - - path to the directory
Returns:
List of SFtpFiles
Throws:
SFtpClientException

list

List<SFtpFile> list()
                    throws SFtpClientException
Returns list of files available in the current working directory on the Remote server

Returns:
List of SFtpFiles
Throws:
SFtpClientException

get

InputStream get(String remotePath,
                SFtpFileTransferMode mode)
                throws SFtpClientException
Retrieves the file given the path as a stream

Parameters:
remotePath - - path to the file
mode - - File transfer mode (Binary/ASCII)
Returns:
file as a stream
Throws:
SFtpClientException

get

void get(String remotePath,
         String localPath,
         SFtpFileTransferMode mode)
         throws SFtpClientException
Retrieves the file on the remote server and copies it on to the local file system

Parameters:
remotePath - - path to the file on the remote server
localPath - - Path where to copy in the local file system
mode - - File transfer mode (Binary/ASCII)
Throws:
SFtpClientException

get

void get(String remotePath,
         OutputStream outStream,
         SFtpFileTransferMode mode)
         throws SFtpClientException
Retrieves the file on the remote server and copies it to a stream

Parameters:
remotePath - - path to the file on the remote server
outStream - - stream where to copy the remote file
mode - - File transfer mode (Binary/ASCII)
Throws:
SFtpClientException

put

void put(String localPath,
         String remotePath,
         SFtpFileTransferMode mode)
         throws SFtpClientException
Copies the local file on to the remote server

Parameters:
localPath - - path to the local file
remotePath - - path to the remote file
mode - - File transfer mode (Binary/ASCII)
Throws:
SFtpClientException

put

void put(InputStream inStream,
         String remotePath,
         SFtpFileTransferMode mode)
         throws SFtpClientException
Copies the stream on to the remote server

Parameters:
inStream - - stream containing the file
remotePath - - path to the remote file
mode - - File transfer mode (Binary/ASCII)
Throws:
SFtpClientException

disconnect

void disconnect()
                throws SFtpClientException
Disconnects from the remote server and cleans up the resources

Throws:
SFtpClientException