|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.maverick.ssh.SubsystemChannel
com.maverick.sftp.SftpSubsystemChannel
This class implements the SFTP protocol which is executed as an SSH subsystem. The basic initialization procedure is as follows:
The above example demonstrates how to execute subsystem on both SSH1 and SSH2 connections. There is no subsystem support within SSH1 which requires that the command is executed directly.// Create an SshClient SshConnector con = SshConnector.getInstance(); // Connect and authenticate an SshClient SshClient ssh = con.connect(....); .... // Create and initialize an SftpSubsystemChannel SshSession session = ssh.openSessionChannel(); if(session instanceof Ssh2Session) ((Ssh2Session)session).startSubsystem("sftp"); else session.executeCommand("/usr/sbin/sftp-server"); SftpSubsystemChannel sftp = new SftpSubsystemChannel(session); sftp.initialize();
Field Summary | |
static int |
OPEN_APPEND
File open flag, forces all writes to append data at the end of the file. |
static int |
OPEN_CREATE
File open flag, if specified a new file will be created if one does not already exist. |
static int |
OPEN_EXCLUSIVE
File open flag, causes an open request to fail if the named file already exists. |
static int |
OPEN_READ
File open flag, opens the file for reading. |
static int |
OPEN_TEXT
File open flag, causes the file to be opened in text mode. |
static int |
OPEN_TRUNCATE
File open flag, forces an existing file with the same name to be truncated to zero length when creating a file by specifying OPEN_CREATE. |
static int |
OPEN_WRITE
File open flag, opens the file for writing. |
Constructor Summary | |
SftpSubsystemChannel(SshSession session)
Constructs an uninitialized sftp channel with an unitialized session channel |
Method Summary | |
void |
changePermissions(SftpFile file,
int permissions)
Change the permissions of a file. |
void |
changePermissions(java.lang.String filename,
int permissions)
Change the permissions of a file. |
void |
changePermissions(java.lang.String filename,
java.lang.String permissions)
Change the permissions of a file. |
void |
closeFile(SftpFile file)
Close a file or directory. |
void |
createSymbolicLink(java.lang.String targetpath,
java.lang.String linkpath)
Create a symbolic link. |
java.lang.String |
getAbsolutePath(SftpFile file)
Get the absolute path of a file. |
java.lang.String |
getAbsolutePath(java.lang.String path)
Get the absolute path of a file. |
SftpFileAttributes |
getAttributes(SftpFile file)
Get the attributes of a file. |
SftpFileAttributes |
getAttributes(java.lang.String path)
Get the attributes of a file. |
java.lang.String |
getCanonicalNewline()
Returns the canonical newline convention in use when reading/writing text files. |
java.lang.String |
getCharsetEncoding()
Get the current encoding being used for filename Strings. |
java.lang.String |
getDefaultDirectory()
Gets the users default directory. |
java.lang.String |
getExtension(java.lang.String name)
Get the data value of a supported SFTP extension. |
SftpFile |
getFile(java.lang.String path)
Utility method to obtain an SftpFile instance for a given path. |
void |
getOKRequestStatus(com.maverick.crypto.io.UnsignedInteger32 requestId)
Verify that an OK status has been returned for a request id. |
int |
getServerVersion()
Version 4 of the SFTP protocol allows the server to return its maximum supported version instead of the actual version to be used. |
java.lang.String |
getSymbolicLinkTarget(java.lang.String linkpath)
Get the target path of a symbolic link. |
int |
getVersion()
When called after the initialize method this will return the version in operation for this sftp session. |
void |
initialize()
Initializes the sftp subsystem and negotiates a version with the server. |
int |
listChildren(SftpFile file,
java.util.Vector children)
List the children of a directory. |
void |
makeDirectory(java.lang.String path)
Make a directory. |
void |
makeDirectory(java.lang.String path,
SftpFileAttributes attrs)
Make a directory. |
SftpFile |
openDirectory(java.lang.String path)
Open a directory. |
SftpFile |
openFile(java.lang.String absolutePath,
int flags)
Open a file. |
SftpFile |
openFile(java.lang.String absolutePath,
int flags,
SftpFileAttributes attrs)
Open a file. |
void |
performOptimizedRead(byte[] handle,
long length,
int blocksize,
java.io.OutputStream out,
int outstandingRequests,
FileTransferProgress progress)
Performs an optimized read of a file through use of asynchronous messages. |
void |
performOptimizedRead(byte[] handle,
long length,
int blocksize,
java.io.OutputStream out,
int outstandingRequests,
FileTransferProgress progress,
long position)
Performs an optimized read of a file through use of asynchronous messages. |
void |
performOptimizedWrite(byte[] handle,
int blocksize,
int outstandingRequests,
java.io.InputStream in,
int buffersize,
FileTransferProgress progress)
Performs an optimized write of a file through asynchronous messaging and through buffering the local file into memory. |
void |
performOptimizedWrite(byte[] handle,
int blocksize,
int outstandingRequests,
java.io.InputStream in,
int buffersize,
FileTransferProgress progress,
long position)
Performs an optimized write of a file through asynchronous messaging and through buffering the local file into memory. |
com.maverick.crypto.io.UnsignedInteger32 |
postReadRequest(byte[] handle,
long offset,
int len)
Post a read request to the server and return the request id; this is used to optimize file downloads. |
com.maverick.crypto.io.UnsignedInteger32 |
postWriteRequest(byte[] handle,
long position,
byte[] data,
int off,
int len)
Send a write request for an open file but do not wait for the response from the server. |
int |
readFile(byte[] handle,
com.maverick.crypto.io.UnsignedInteger64 offset,
byte[] output,
int off,
int len)
Read a block of data from an open file. |
void |
recurseMakeDirectory(java.lang.String path)
Recurse through a hierarchy of directories creating them as necersary. |
void |
removeDirectory(java.lang.String path)
Remove an empty directory. |
void |
removeFile(java.lang.String filename)
Remove a file. |
void |
renameFile(java.lang.String oldpath,
java.lang.String newpath)
Rename an existing file. |
SftpMessage |
sendExtensionMessage(java.lang.String request,
byte[] requestData)
Send an extension message and return the response. |
void |
setAttributes(SftpFile file,
SftpFileAttributes attrs)
Sets the attributes of a file. |
void |
setAttributes(java.lang.String path,
SftpFileAttributes attrs)
Sets the attributes of a file. |
void |
setCharsetEncoding(java.lang.String charset)
Allows the default character encoding to be overriden for filename strings. |
boolean |
supportsExtension(java.lang.String name)
Does the server support an SFTP extension? This checks the extensions returned by the server during the SFTP version negotiation. |
void |
writeFile(byte[] handle,
com.maverick.crypto.io.UnsignedInteger64 offset,
byte[] data,
int off,
int len)
Write a block of data to an open file. |
Methods inherited from class com.maverick.ssh.SubsystemChannel |
close, createPacket, isClosed, nextMessage, sendMessage, sendMessage |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int OPEN_READ
public static final int OPEN_WRITE
public static final int OPEN_APPEND
public static final int OPEN_CREATE
public static final int OPEN_TRUNCATE
public static final int OPEN_EXCLUSIVE
public static final int OPEN_TEXT
Constructor Detail |
public SftpSubsystemChannel(SshSession session) throws SshException
SshException
Method Detail |
public int getVersion()
public java.lang.String getCanonicalNewline() throws SftpStatusException
SftpStatusException
public void initialize() throws SshException, java.io.UnsupportedEncodingException
SshException
java.io.UnsupportedEncodingException
public void setCharsetEncoding(java.lang.String charset) throws SshException, java.io.UnsupportedEncodingException
charset
-
java.io.UnsupportedEncodingException
SshException
public int getServerVersion()
public java.lang.String getCharsetEncoding()
public boolean supportsExtension(java.lang.String name)
name
- String
public java.lang.String getExtension(java.lang.String name)
supportsExtension(String)
before calling this method to determine if the extension is available.
name
- String
public SftpMessage sendExtensionMessage(java.lang.String request, byte[] requestData) throws SshException, SftpStatusException
request
- StringrequestData
- byte[]
SshException
SftpStatusException
public void changePermissions(SftpFile file, int permissions) throws SftpStatusException, SshException
file
- the filepermissions
- an integer value containing a file permissions mask
SshException
SftpStatusException
public void changePermissions(java.lang.String filename, int permissions) throws SftpStatusException, SshException
filename
- the path to the file.permissions
- an integer value containing a file permissions mask.
SshException
SftpStatusException
public void changePermissions(java.lang.String filename, java.lang.String permissions) throws SftpStatusException, SshException
filename
- the path to the file.permissions
- a string containing the permissions, for example "rw-r--r--"
SshException
SftpStatusException
public void setAttributes(java.lang.String path, SftpFileAttributes attrs) throws SftpStatusException, SshException
path
- the path to the file.attrs
- the file attributes.
SshException
SftpStatusException
public void setAttributes(SftpFile file, SftpFileAttributes attrs) throws SftpStatusException, SshException
file
- the file object.attrs
- the new attributes.
SshException
SftpStatusException
public com.maverick.crypto.io.UnsignedInteger32 postWriteRequest(byte[] handle, long position, byte[] data, int off, int len) throws SftpStatusException, SshException
handle
- position
- data
- off
- len
-
SshException
SftpStatusException
public void writeFile(byte[] handle, com.maverick.crypto.io.UnsignedInteger64 offset, byte[] data, int off, int len) throws SftpStatusException, SshException
handle
- the open file handle.offset
- the offset in the file to start writingdata
- a buffer containing the data to writeoff
- the offset to start in the bufferlen
- the lenght of data to write
(setting to false will increase file transfer but may miss errors)
SshException
SftpStatusException
public void performOptimizedWrite(byte[] handle, int blocksize, int outstandingRequests, java.io.InputStream in, int buffersize, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException
handle
- the open file handle to write toblocksize
- the block size to send data, should be between 4096 and 65535outstandingRequests
- the maximum number of requests that can be outstanding at any one timein
- the InputStream to read frombuffersize
- the size of the temporary buffer to read from the InputStream. Data is buffered
into a temporary buffer so that the number of local filesystem reads is reducted to a minimum. This
increases performance and so the buffer size should be as high as possible. The default operation, if
buffersize <= 0 is to allocate a buffer the same size as the blocksize, meaning no buffer optimization
is performed.progress
- provides progress information, may be null.
SshException
SftpStatusException
TransferCancelledException
public void performOptimizedWrite(byte[] handle, int blocksize, int outstandingRequests, java.io.InputStream in, int buffersize, FileTransferProgress progress, long position) throws SftpStatusException, SshException, TransferCancelledException
handle
- the open file handle to write toblocksize
- the block size to send data, should be between 4096 and 65535outstandingRequests
- the maximum number of requests that can be outstanding at any one timein
- the InputStream to read frombuffersize
- the size of the temporary buffer to read from the InputStream. Data is buffered
into a temporary buffer so that the number of local filesystem reads is reducted to a minimum. This
increases performance and so the buffer size should be as high as possible. The default operation, if
buffersize <= 0 is to allocate a buffer the same size as the blocksize, meaning no buffer optimization
is performed.progress
- provides progress information, may be null.position
- the position in the file to start writing to.
SshException
SftpStatusException
TransferCancelledException
public void performOptimizedRead(byte[] handle, long length, int blocksize, java.io.OutputStream out, int outstandingRequests, FileTransferProgress progress) throws SftpStatusException, SshException, TransferCancelledException
handle
- the open files handlelength
- the length of the fileblocksize
- the blocksize to readout
- an OutputStream to output the file intooutstandingRequests
- the maximum number of read requests toprogress
-
SshException
SftpStatusException
TransferCancelledException
public void performOptimizedRead(byte[] handle, long length, int blocksize, java.io.OutputStream out, int outstandingRequests, FileTransferProgress progress, long position) throws SftpStatusException, SshException, TransferCancelledException
handle
- the open files handlelength
- the length of the fileblocksize
- the blocksize to readout
- an OutputStream to output the file intooutstandingRequests
- the maximum number of read requests toprogress
- position
- the postition from which to start reading the file
SshException
SftpStatusException
TransferCancelledException
public com.maverick.crypto.io.UnsignedInteger32 postReadRequest(byte[] handle, long offset, int len) throws SftpStatusException, SshException
handle
- offset
- len
-
SshException
SftpStatusException
public int readFile(byte[] handle, com.maverick.crypto.io.UnsignedInteger64 offset, byte[] output, int off, int len) throws SftpStatusException, SshException
handle
- the open file handleoffset
- the offset to start reading in the fileoutput
- a buffer to write the returned data tooff
- the starting offset in the output bufferlen
- the length of data to read
SshException
SftpStatusException
public SftpFile getFile(java.lang.String path) throws SftpStatusException, SshException
SftpFile
instance for a given path.
path
-
SftpStatusException
SshException
public java.lang.String getAbsolutePath(SftpFile file) throws SftpStatusException, SshException
file
-
SshException
SftpStatusException
public void createSymbolicLink(java.lang.String targetpath, java.lang.String linkpath) throws SftpStatusException, SshException
targetpath
- the symbolic link to createlinkpath
- the path to which the symbolic link points
SshException
- if the remote SFTP version is < 3 an exception is thrown as
this feature is not supported by previous versions of the protocol.
SftpStatusException
public java.lang.String getSymbolicLinkTarget(java.lang.String linkpath) throws SftpStatusException, SshException
linkpath
-
SshException
- if the remote SFTP version is < 3 an exception is thrown as
this feature is not supported by previous versions of the protocol.
SftpStatusException
public java.lang.String getDefaultDirectory() throws SftpStatusException, SshException
SshException
SftpStatusException
public java.lang.String getAbsolutePath(java.lang.String path) throws SftpStatusException, SshException
path
-
SshException
SftpStatusException
public int listChildren(SftpFile file, java.util.Vector children) throws SftpStatusException, SshException
List the children of a directory.
To use this method first open a directory with the openDirectory method and then create a Vector to store the results. To retreive the results keep calling this method unitll it returns -1 which indicates no more results will be returned.
SftpFile dir = sftp.openDirectory("code/foobar"); Vector results = new Vector(); while(sftp.listChildren(dir, results) > -1); sftp.closeFile(dir);
file
- children
-
SshException
SftpStatusException
public void recurseMakeDirectory(java.lang.String path) throws SftpStatusException, SshException
path
-
SshException
SftpStatusException
public SftpFile openFile(java.lang.String absolutePath, int flags) throws SftpStatusException, SshException
absolutePath
- flags
-
SshException
SftpStatusException
public SftpFile openFile(java.lang.String absolutePath, int flags, SftpFileAttributes attrs) throws SftpStatusException, SshException
absolutePath
- flags
- attrs
-
SshException
SftpStatusException
public SftpFile openDirectory(java.lang.String path) throws SftpStatusException, SshException
path
-
SshException
SftpStatusException
public void closeFile(SftpFile file) throws SftpStatusException, SshException
file
-
SshException
SftpStatusException
public void removeDirectory(java.lang.String path) throws SftpStatusException, SshException
path
-
SshException
SftpStatusException
public void removeFile(java.lang.String filename) throws SftpStatusException, SshException
filename
-
SshException
SftpStatusException
public void renameFile(java.lang.String oldpath, java.lang.String newpath) throws SftpStatusException, SshException
oldpath
- newpath
-
SshException
SftpStatusException
public SftpFileAttributes getAttributes(java.lang.String path) throws SftpStatusException, SshException
path
-
SshException
SftpStatusException
public SftpFileAttributes getAttributes(SftpFile file) throws SftpStatusException, SshException
file
-
SshException
SftpStatusException
public void makeDirectory(java.lang.String path) throws SftpStatusException, SshException
path
-
SshException
SftpStatusException
public void makeDirectory(java.lang.String path, SftpFileAttributes attrs) throws SftpStatusException, SshException
path
- attrs
-
SshException
SftpStatusException
public void getOKRequestStatus(com.maverick.crypto.io.UnsignedInteger32 requestId) throws SftpStatusException, SshException
requestId
-
SshException
SftpStatusException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |