Secure iNet Factory

com.jscape.inet.sftp
Class SftpClient

java.lang.Object
  extended by com.jscape.inet.sftp.SftpClient
All Implemented Interfaces:
JFileSystem
Direct Known Subclasses:
SftpClient2

public class SftpClient
extends java.lang.Object
implements JFileSystem

The SFTP client. Takes responsibility for protocol request/response exchange and transform occured errors to the appropriate exceptions.

Author:
Alex Usun

Field Summary
static int VERSION
          The client version
 
Constructor Summary
SftpClient(com.jscape.inet.util.connection.Connection connection, SftpConfiguration config)
          Creates a new client instance.
 
Method Summary
 void close()
          Closes the current client.
 void close(byte[] handle)
          Closes the file or directory handle.
 boolean containsExtension(java.lang.String name)
          Checks if the client contains the specified server extension.
static SftpClient create(java.lang.Class clientClass, com.jscape.inet.util.connection.Connection connection, SftpConfiguration config)
          Creates a SFTP client instance.
 SftpFileAttributes fstat(byte[] handle)
          Obtains the remote file attributes.
 java.lang.String getCharset()
           
 com.jscape.inet.util.connection.Connection getConnection()
          Returns the client session channel.
 byte[] getExtension(java.lang.String name)
          Obtains the specified server extension.
 JFile getFile(JFile parent, java.lang.String child)
          Creates a new JFile instance from a parent abstract pathname and a child pathname string.
 JFile getFile(JFile parent, java.lang.String child, SftpFileAttributes attrs)
          Creates a new JFile instance from a parent abstract pathname and a child pathname string.
 JFile getFile(java.lang.String pathname)
          Creates a new JFile instance by converting the given pathname string into an abstract pathname.
 java.lang.String getStringExtension(java.lang.String name)
          Obtains the specified string server extension.
 int getVersion()
          Returns the client protocol version.
 boolean isClosed()
          Checks if the current client is already closed.
 boolean knowsPacket(int type)
          Checks if the client knows this packet, i.e.
 SftpFileAttributes lstat(java.lang.String path)
          Obtains the link target attributes.
 void mkdir(java.lang.String path, SftpFileAttributes attrs)
          Creates a new directory.
 byte[] open(java.lang.String path, JFileOpenFlags flags, JAcl.Mask accessType, SftpFileAttributes attrs)
          Opens or creates the file.
 byte[] opendir(java.lang.String path)
          Opens the remote directory for listing.
 byte[] read(byte[] handle, long offset, int len)
          Reads the file content.
 SftpName[] readdir(byte[] handle)
          Reads the directory content.
 java.lang.String realPath(java.lang.String path)
          Obtains the real file path in the remote system.
 void registerPacket(int type, java.lang.Class packetClass)
          Adds the packet to the client.
 void remove(java.lang.String fileName)
          Deletes the file.
 void rmdir(java.lang.String path)
          Removes the directory.
 SftpPacket sendRequest(SftpPacket request)
          Sends the request to the server.
 void setCharset(java.lang.String charset)
           
 void setFstat(byte[] handle, SftpFileAttributes attrs)
          Setups the remote file attributes.
 void setStat(java.lang.String path, SftpFileAttributes attrs)
          Setups the remote file attributes.
 SftpFileAttributes stat(java.lang.String path)
          Obtains the remote file attributes.
 void unregisterPacket(int type)
          Removes the packet from the client.
 void write(byte[] handle, long offset, byte[] data)
          Writes the data to the file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
The client version

See Also:
Constant Field Values
Constructor Detail

SftpClient

public SftpClient(com.jscape.inet.util.connection.Connection connection,
                  SftpConfiguration config)
           throws java.io.IOException
Creates a new client instance.

Parameters:
connection - the session connection
config - the configuration
Throws:
SftpException - if an I/O or SFTP error occurs.
java.io.IOException
Method Detail

create

public static SftpClient create(java.lang.Class clientClass,
                                com.jscape.inet.util.connection.Connection connection,
                                SftpConfiguration config)
                         throws SftpException
Creates a SFTP client instance.

Parameters:
clientClass - the target client class
connection - the connection
config - the SFTP configuration
Returns:
a created client instance
Throws:
SftpException - if an I/O or protocol error occurs

registerPacket

public void registerPacket(int type,
                           java.lang.Class packetClass)
Adds the packet to the client. After this operation the client can read the specified packet.

Parameters:
type - the packet type
packetClass - the packet class

unregisterPacket

public void unregisterPacket(int type)
Removes the packet from the client. After this operation the client cannot read the specified packet.

Parameters:
type -

knowsPacket

public boolean knowsPacket(int type)
Checks if the client knows this packet, i.e. can read it.

Parameters:
type - the packet type
Returns:
true if the packet is registered; false otherwise

close

public void close()
Closes the current client.

Specified by:
close in interface JFileSystem

isClosed

public boolean isClosed()
Checks if the current client is already closed.

Specified by:
isClosed in interface JFileSystem
Returns:
true if the client is closed; false otherwise

getVersion

public int getVersion()
Returns the client protocol version.

Returns:
the client protocol version

getConnection

public com.jscape.inet.util.connection.Connection getConnection()
Returns the client session channel.

Returns:
the client session channel

containsExtension

public boolean containsExtension(java.lang.String name)
Checks if the client contains the specified server extension.

Parameters:
name - the server extension name
Returns:
true if the client contains extension; false otherwise

getExtension

public byte[] getExtension(java.lang.String name)
Obtains the specified server extension.

Parameters:
name - the server extension to obtain
Returns:
the server extension data

getStringExtension

public java.lang.String getStringExtension(java.lang.String name)
Obtains the specified string server extension.

Parameters:
name - the server extension to obtain
Returns:
the string server extension data

getFile

public JFile getFile(java.lang.String pathname)
Creates a new JFile instance by converting the given pathname string into an abstract pathname.

Specified by:
getFile in interface JFileSystem
Parameters:
pathname - a pathname string
Returns:
a new JFile instance

getFile

public JFile getFile(JFile parent,
                     java.lang.String child)
Creates a new JFile instance from a parent abstract pathname and a child pathname string.

Specified by:
getFile in interface JFileSystem
Parameters:
parent - the parent abstract pathname
child - the child pathname string
Returns:
a new JFile instance

getFile

public JFile getFile(JFile parent,
                     java.lang.String child,
                     SftpFileAttributes attrs)
Creates a new JFile instance from a parent abstract pathname and a child pathname string.

Parameters:
parent - the parent abstract pathname
child - the child pathname string
attrs -
Returns:
a new JFile instance

sendRequest

public SftpPacket sendRequest(SftpPacket request)
                       throws SftpException
Sends the request to the server.

Parameters:
request - the request to send
Returns:
the server response
Throws:
SftpException - if an I/O or SFTP error occurs.

open

public byte[] open(java.lang.String path,
                   JFileOpenFlags flags,
                   JAcl.Mask accessType,
                   SftpFileAttributes attrs)
            throws SftpException
Opens or creates the file.

Parameters:
path - the file path
flags - the open flags
accessType - file access type
attrs - the file attributes
Returns:
a file handle
Throws:
SftpException - if an I/O or SFTP error occurs.

close

public void close(byte[] handle)
           throws SftpException
Closes the file or directory handle.

Parameters:
handle - the handle to close
Throws:
SftpException - if an I/O or SFTP error occurs.

read

public byte[] read(byte[] handle,
                   long offset,
                   int len)
            throws SftpException
Reads the file content.

Parameters:
handle - the file handle
offset - the file offset
len - desired data length
Returns:
the readed data
Throws:
SftpException - if an I/O or SFTP error occurs.

write

public void write(byte[] handle,
                  long offset,
                  byte[] data)
           throws SftpException
Writes the data to the file.

Parameters:
handle - the file handle
offset - the file offset
data - the data to write
Throws:
SftpException - if an I/O or SFTP error occurs.

remove

public void remove(java.lang.String fileName)
            throws SftpException
Deletes the file.

Parameters:
fileName - the file to delete
Throws:
SftpException - if an I/O or SFTP error occurs.

mkdir

public void mkdir(java.lang.String path,
                  SftpFileAttributes attrs)
           throws SftpException
Creates a new directory.

Parameters:
path - the directory path
attrs - the directory attributes
Throws:
SftpException - if an I/O or SFTP error occurs.

rmdir

public void rmdir(java.lang.String path)
           throws SftpException
Removes the directory.

Parameters:
path - the directory to remove
Throws:
SftpException - if an I/O or SFTP error occurs.

opendir

public byte[] opendir(java.lang.String path)
               throws SftpException
Opens the remote directory for listing.

Parameters:
path - the directory path
Returns:
a directory handle
Throws:
SftpException - if an I/O or SFTP error occurs.

readdir

public SftpName[] readdir(byte[] handle)
                   throws SftpException
Reads the directory content.

Parameters:
handle - the directory handle
Returns:
the array of the files
Throws:
SftpException - if an I/O or SFTP error occurs.

stat

public SftpFileAttributes stat(java.lang.String path)
                        throws SftpException
Obtains the remote file attributes.

Parameters:
path - the file path
Returns:
the file attributes
Throws:
SftpException - if an I/O or SFTP error occurs.

lstat

public SftpFileAttributes lstat(java.lang.String path)
                         throws SftpException
Obtains the link target attributes.

Parameters:
path - the link path
Returns:
the file attributes
Throws:
SftpException - if an I/O or SFTP error occurs.

fstat

public SftpFileAttributes fstat(byte[] handle)
                         throws SftpException
Obtains the remote file attributes.

Parameters:
handle - the file handle
Returns:
the file attributes
Throws:
SftpException - if an I/O or SFTP error occurs.

setStat

public void setStat(java.lang.String path,
                    SftpFileAttributes attrs)
             throws SftpException
Setups the remote file attributes.

Parameters:
path - the file path
attrs - desired file attributes
Throws:
SftpException - if an I/O or SFTP error occurs.

setFstat

public void setFstat(byte[] handle,
                     SftpFileAttributes attrs)
              throws SftpException
Setups the remote file attributes.

Parameters:
handle - the file handle
attrs - desired file attributes
Throws:
SftpException - if an I/O or SFTP error occurs.

realPath

public java.lang.String realPath(java.lang.String path)
                          throws SftpException
Obtains the real file path in the remote system.

Parameters:
path - the file path
Returns:
the real remote file path
Throws:
SftpException - if an I/O or SFTP error occurs.

getCharset

public java.lang.String getCharset()

setCharset

public void setCharset(java.lang.String charset)

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved