public class SftpChannel extends AbstractSubsystem
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_VERSION |
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.
|
static int |
SSH_FXF_ACCESS_APPEND_DATA |
static int |
SSH_FXF_ACCESS_APPEND_DATA_ATOMIC |
static int |
SSH_FXF_ACCESS_AUDIT_ALARM_INFO |
static int |
SSH_FXF_ACCESS_BACKUP |
static int |
SSH_FXF_ACCESS_BLOCK_ADVISORY |
static int |
SSH_FXF_ACCESS_BLOCK_DELETE |
static int |
SSH_FXF_ACCESS_BLOCK_READ |
static int |
SSH_FXF_ACCESS_BLOCK_WRITE |
static int |
SSH_FXF_ACCESS_DISPOSITION
Version 5 new flags
|
static int |
SSH_FXF_ACCESS_TEXT_MODE |
static int |
SSH_FXF_BACKUP_STREAM |
static int |
SSH_FXF_CREATE_NEW |
static int |
SSH_FXF_CREATE_TRUNCATE |
static int |
SSH_FXF_DELETE_ON_CLOSE |
static int |
SSH_FXF_NOFOLLOW |
static int |
SSH_FXF_OPEN_EXISTING |
static int |
SSH_FXF_OPEN_OR_CREATE |
static int |
SSH_FXF_OVERRIDE_OWNER |
static int |
SSH_FXF_TRUNCATE_EXISTING |
static int |
SSH_FXP_ATTRS |
static int |
SSH_FXP_DATA |
static int |
SSH_FXP_EXTENDED |
static int |
SSH_FXP_EXTENDED_REPLY |
static int |
SSH_FXP_HANDLE |
static int |
SSH_FXP_NAME |
static int |
SSH_FXP_RENAME_ATOMIC |
static int |
SSH_FXP_RENAME_NATIVE |
static int |
SSH_FXP_RENAME_OVERWRITE |
static int |
SSH_FXP_STATUS |
con, session, timeout| Constructor and Description |
|---|
SftpChannel(SshConnection con) |
| Modifier and Type | Method and Description |
|---|---|
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 |
close() |
void |
closeFile(SftpFile file)
Close a file or directory.
|
void |
createLink(java.lang.String targetpath,
java.lang.String linkpath,
boolean symbolic)
Create a symbolic link.
|
protected Packet |
createPacket()
Get a packet from the available pool or create if non available
|
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.
|
protected SftpFileAttributes |
getAttributes(java.lang.String path,
int messageId) |
byte[] |
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.
|
byte[] |
getExtension(java.lang.String name)
Get the data value of a supported SFTP extension.
|
java.util.Map<java.lang.String,byte[]> |
getExtensions() |
SftpFile |
getFile(java.lang.String path)
Utility method to obtain an
SftpFile instance for a given path. |
byte[] |
getHandleResponse(SftpMessage bar) |
byte[] |
getHandleResponse(com.sshtools.common.util.UnsignedInteger32 requestId) |
SftpFileAttributes |
getLinkAttributes(java.lang.String path)
Get the attributes of a file.
|
int |
getMaximumLocalPacketLength() |
int |
getMaximumLocalWindowSize() |
protected int |
getMaximumPacketSize() |
int |
getMaximumRemotePacketLength() |
int |
getMaximumRemoteWindowSize() |
protected int |
getMaximumWindowSize() |
protected int |
getMinimumWindowSize() |
void |
getOKRequestStatus(com.sshtools.common.util.UnsignedInteger32 requestId)
Verify that an OK status has been returned for a request id.
|
SftpMessage |
getResponse(com.sshtools.common.util.UnsignedInteger32 requestId) |
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.
|
SftpFile |
getSingleFileResponse(SftpMessage bar,
java.lang.String messageName)
Get a single SftpFile object from a message returning SSH_FXP_NAME result.
|
java.lang.String |
getSymbolicLinkTarget(java.lang.String linkpath)
Get the target path of a symbolic link.
|
int |
getVersion() |
boolean |
isClosed() |
int |
listChildren(SftpFile file,
java.util.List<SftpFile> children)
List the children of a directory.
|
void |
lockFile(byte[] handle,
long offset,
long length,
int lockFlags) |
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.
|
SftpFile |
openFileVersion5(java.lang.String absolutePath,
int flags,
int accessFlags,
SftpFileAttributes attrs) |
void |
performOptimizedRead(java.lang.String filename,
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(java.lang.String filename,
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(java.lang.String filename,
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(java.lang.String filename,
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.
|
void |
performSynchronousRead(byte[] handle,
int blocksize,
java.io.OutputStream out,
FileTransferProgress progress,
long position)
Perform a synchronous read of a file from the remote file system.
|
com.sshtools.common.util.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.sshtools.common.util.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.
|
protected void |
processSupported(byte[] data) |
protected void |
processSupported2(byte[] data) |
int |
readFile(byte[] handle,
com.sshtools.common.util.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 necessary.
|
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.
|
void |
renameFile(java.lang.String oldpath,
java.lang.String newpath,
int flags) |
com.sshtools.common.util.UnsignedInteger32 |
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 |
unlockFile(byte[] handle,
long offset,
long length) |
void |
writeFile(byte[] handle,
com.sshtools.common.util.UnsignedInteger64 offset,
byte[] data,
int off,
int len)
Write a block of data to an open file.
|
getSession, nextMessage, onCloseSession, sendMessagepublic 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
public static final int SSH_FXP_STATUS
public static final int SSH_FXP_HANDLE
public static final int SSH_FXP_DATA
public static final int SSH_FXP_NAME
public static final int SSH_FXP_ATTRS
public static final int SSH_FXP_EXTENDED
public static final int SSH_FXP_EXTENDED_REPLY
public static final int MAX_VERSION
public static final int SSH_FXF_ACCESS_DISPOSITION
public static final int SSH_FXF_CREATE_NEW
public static final int SSH_FXF_CREATE_TRUNCATE
public static final int SSH_FXF_OPEN_EXISTING
public static final int SSH_FXF_OPEN_OR_CREATE
public static final int SSH_FXF_TRUNCATE_EXISTING
public static final int SSH_FXF_ACCESS_APPEND_DATA
public static final int SSH_FXF_ACCESS_APPEND_DATA_ATOMIC
public static final int SSH_FXF_ACCESS_TEXT_MODE
public static final int SSH_FXF_ACCESS_BLOCK_READ
public static final int SSH_FXF_ACCESS_BLOCK_WRITE
public static final int SSH_FXF_ACCESS_BLOCK_DELETE
public static final int SSH_FXF_ACCESS_BLOCK_ADVISORY
public static final int SSH_FXF_NOFOLLOW
public static final int SSH_FXF_DELETE_ON_CLOSE
public static final int SSH_FXF_ACCESS_AUDIT_ALARM_INFO
public static final int SSH_FXF_ACCESS_BACKUP
public static final int SSH_FXF_BACKUP_STREAM
public static final int SSH_FXF_OVERRIDE_OWNER
public static final int SSH_FXP_RENAME_OVERWRITE
public static final int SSH_FXP_RENAME_ATOMIC
public static final int SSH_FXP_RENAME_NATIVE
public SftpChannel(SshConnection con) throws SshException
SshExceptionpublic int getVersion()
protected int getMinimumWindowSize()
getMinimumWindowSize in class AbstractSubsystemprotected int getMaximumWindowSize()
getMaximumWindowSize in class AbstractSubsystemprotected int getMaximumPacketSize()
getMaximumPacketSize in class AbstractSubsystempublic java.util.Map<java.lang.String,byte[]> getExtensions()
public byte[] getCanonicalNewline()
throws SftpStatusException
SftpStatusExceptionprotected void processSupported2(byte[] data)
throws java.io.IOException
java.io.IOExceptionprotected void processSupported(byte[] data)
throws java.io.IOException
java.io.IOExceptionpublic void setCharsetEncoding(java.lang.String charset)
throws SshException,
java.io.UnsupportedEncodingException
charset - java.io.UnsupportedEncodingExceptionSshExceptionpublic int getServerVersion()
public java.lang.String getCharsetEncoding()
public boolean supportsExtension(java.lang.String name)
name - Stringpublic byte[] getExtension(java.lang.String name)
supportsExtension(String) before calling this method to determine if the
extension is available.name - Stringpublic void close()
public SftpMessage getResponse(com.sshtools.common.util.UnsignedInteger32 requestId) throws SshException
SshExceptionpublic void changePermissions(SftpFile file, int permissions) throws SftpStatusException, SshException
file - the filepermissions - an integer value containing a file permissions maskSshException - ,SftpStatusExceptionSftpStatusExceptionpublic 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 - ,SftpStatusExceptionSftpStatusExceptionpublic 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--"SftpStatusException - , SshExceptionSshExceptionpublic void getOKRequestStatus(com.sshtools.common.util.UnsignedInteger32 requestId)
throws SftpStatusException,
SshException
requestId - SftpStatusException - , SshExceptionSshExceptionpublic void setAttributes(java.lang.String path,
SftpFileAttributes attrs)
throws SftpStatusException,
SshException
path - the path to the file.attrs - the file attributes.SftpStatusException - , SshExceptionSshExceptionpublic void setAttributes(SftpFile file, SftpFileAttributes attrs) throws SftpStatusException, SshException
file - the file object.attrs - the new attributes.SshExceptionSftpStatusExceptionpublic com.sshtools.common.util.UnsignedInteger32 postWriteRequest(byte[] handle,
long position,
byte[] data,
int off,
int len)
throws SftpStatusException,
SshException
handle - position - data - off - len - SshExceptionSftpStatusExceptionpublic void writeFile(byte[] handle,
com.sshtools.common.util.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 length of data to write (setting to false will increase
file transfer but may miss errors)SshExceptionSftpStatusExceptionpublic void performOptimizedWrite(java.lang.String filename,
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 65536outstandingRequests - 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.SshExceptionSftpStatusExceptionTransferCancelledExceptionpublic void performOptimizedWrite(java.lang.String filename,
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 65536outstandingRequests - 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.SshExceptionSftpStatusExceptionTransferCancelledExceptionpublic void performOptimizedRead(java.lang.String filename,
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 - SshExceptionSftpStatusExceptionTransferCancelledExceptionpublic void performOptimizedRead(java.lang.String filename,
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 amount of the file file to be read, equal to the file
length when reading the whole 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 fileSshExceptionSftpStatusExceptionTransferCancelledExceptionpublic void performSynchronousRead(byte[] handle,
int blocksize,
java.io.OutputStream out,
FileTransferProgress progress,
long position)
throws SftpStatusException,
SshException,
TransferCancelledException
handle - blocksize - out - progress - position - SftpStatusExceptionSshExceptionTransferCancelledExceptionpublic com.sshtools.common.util.UnsignedInteger32 postReadRequest(byte[] handle,
long offset,
int len)
throws SftpStatusException,
SshException
handle - offset - len - SshExceptionSftpStatusExceptionpublic int readFile(byte[] handle,
com.sshtools.common.util.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 readSshExceptionSftpStatusExceptionpublic SftpFile getFile(java.lang.String path) throws SftpStatusException, SshException
SftpFile instance for a given path.path - SftpStatusExceptionSshExceptionpublic java.lang.String getAbsolutePath(SftpFile file) throws SftpStatusException, SshException
file - SshExceptionSftpStatusExceptionpublic void lockFile(byte[] handle,
long offset,
long length,
int lockFlags)
throws SftpStatusException,
SshException
SftpStatusExceptionSshExceptionpublic void unlockFile(byte[] handle,
long offset,
long length)
throws SftpStatusException,
SshException
SftpStatusExceptionSshExceptionpublic 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 pointsSshException - if the remote SFTP version is < 3 an exception is thrown as
this feature is not supported by previous versions of the
protocol.SftpStatusExceptionpublic void createLink(java.lang.String targetpath,
java.lang.String linkpath,
boolean symbolic)
throws SftpStatusException,
SshException
targetpath - the symbolic link to createlinkpath - the path to which the symbolic link pointsSshException - if the remote SFTP version is < 3 an exception is thrown as
this feature is not supported by previous versions of the
protocol.SftpStatusExceptionpublic 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.SftpStatusExceptionpublic java.lang.String getDefaultDirectory()
throws SftpStatusException,
SshException
SshExceptionSftpStatusExceptionpublic java.lang.String getAbsolutePath(java.lang.String path)
throws SftpStatusException,
SshException
path - SshExceptionSftpStatusExceptionpublic SftpFile getSingleFileResponse(SftpMessage bar, java.lang.String messageName) throws SshException, SftpStatusException
bar - messageName - SshExceptionSftpStatusExceptionpublic int listChildren(SftpFile file, java.util.List<SftpFile> 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 retrieve the results keep calling this method until 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 - SftpStatusException - , SshExceptionSshExceptionpublic void recurseMakeDirectory(java.lang.String path)
throws SftpStatusException,
SshException
path - SftpStatusException - , SshExceptionSshExceptionpublic SftpFile openFile(java.lang.String absolutePath, int flags) throws SftpStatusException, SshException
absolutePath - flags - SftpStatusException - , SshExceptionSshExceptionpublic SftpFile openFile(java.lang.String absolutePath, int flags, SftpFileAttributes attrs) throws SftpStatusException, SshException
absolutePath - flags - attrs - SftpStatusException - , SshExceptionSshExceptionpublic SftpFile openFileVersion5(java.lang.String absolutePath, int flags, int accessFlags, SftpFileAttributes attrs) throws SftpStatusException, SshException
SftpStatusExceptionSshExceptionpublic SftpFile openDirectory(java.lang.String path) throws SftpStatusException, SshException
path - SftpStatusException - , SshExceptionSshExceptionpublic void closeFile(SftpFile file) throws SftpStatusException, SshException
file - SftpStatusException - , SshExceptionSshExceptionpublic void removeDirectory(java.lang.String path)
throws SftpStatusException,
SshException
path - SftpStatusException - , SshExceptionSshExceptionpublic void removeFile(java.lang.String filename)
throws SftpStatusException,
SshException
filename - SftpStatusException - , SshExceptionSshExceptionpublic void renameFile(java.lang.String oldpath,
java.lang.String newpath)
throws SftpStatusException,
SshException
oldpath - newpath - SftpStatusException - , SshExceptionSshExceptionpublic void renameFile(java.lang.String oldpath,
java.lang.String newpath,
int flags)
throws SftpStatusException,
SshException
SftpStatusExceptionSshExceptionpublic SftpFileAttributes getAttributes(java.lang.String path) throws SftpStatusException, SshException
path - SshExceptionSftpStatusExceptionpublic SftpFileAttributes getLinkAttributes(java.lang.String path) throws SftpStatusException, SshException
path - SftpStatusExceptionSshExceptionprotected SftpFileAttributes getAttributes(java.lang.String path, int messageId) throws SftpStatusException, SshException
SftpStatusExceptionSshExceptionpublic SftpFileAttributes getAttributes(SftpFile file) throws SftpStatusException, SshException
file - SftpStatusException - , SshExceptionSshExceptionpublic void makeDirectory(java.lang.String path)
throws SftpStatusException,
SshException
path - SftpStatusException - , SshExceptionSshExceptionpublic void makeDirectory(java.lang.String path,
SftpFileAttributes attrs)
throws SftpStatusException,
SshException
path - attrs - SftpStatusException - , SshExceptionSshExceptionpublic byte[] getHandleResponse(com.sshtools.common.util.UnsignedInteger32 requestId)
throws SftpStatusException,
SshException
SftpStatusExceptionSshExceptionpublic byte[] getHandleResponse(SftpMessage bar) throws SftpStatusException, SshException
SftpStatusExceptionSshExceptionpublic com.sshtools.common.util.UnsignedInteger32 sendExtensionMessage(java.lang.String request,
byte[] requestData)
throws SshException,
SftpStatusException
request - StringrequestData - byte[]SshExceptionSftpStatusExceptionprotected Packet createPacket() throws java.io.IOException
java.io.IOExceptionpublic boolean isClosed()
public int getMaximumLocalWindowSize()
public int getMaximumLocalPacketLength()
public int getMaximumRemoteWindowSize()
public int getMaximumRemotePacketLength()
Copyright © 2022. All rights reserved.