Package com.sshtools.client.sftp
Class SftpChannel
java.lang.Object
com.sshtools.client.tasks.AbstractSubsystem
com.sshtools.client.sftp.SftpChannel
Abstract task implementing SFTP operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
File open flag, forces all writes to append data at the end of the file.static final int
File open flag, if specified a new file will be created if one does not already exist.static final int
File open flag, causes an open request to fail if the named file already exists.static final int
File open flag, opens the file for reading.static final int
File open flag, causes the file to be opened in text mode.static final int
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 final int
File open flag, opens the file for writing.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Version 5 new flagsstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class com.sshtools.client.tasks.AbstractSubsystem
con, session, timeout
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
changePermissions
(byte[] file, int permissions) Deprecated, for removal: This API element is subject to removal in a future version.void
changePermissions
(byte[] handle, com.sshtools.common.sftp.PosixPermissions permissions) Change the permissions of a file.void
changePermissions
(String filename, int permissions) Deprecated, for removal: This API element is subject to removal in a future version.void
changePermissions
(String filename, com.sshtools.common.sftp.PosixPermissions permissions) Change the permissions of a file.void
changePermissions
(String filename, String permissions) Change the permissions of a file.void
close()
void
closeFile
(SftpHandle file) Deprecated.void
closeHandle
(byte[] handle) Deprecated.void
createLink
(String targetpath, String linkpath, boolean symbolic) Create a symbolic link.protected com.sshtools.common.ssh.Packet
Get a packet from the available pool or create if non availablevoid
createSymbolicLink
(String targetpath, String linkpath) Create a symbolic link.getAbsolutePath
(SftpFile file) Get the absolute path of a file.getAbsolutePath
(String path) Get the absolute path of a file.com.sshtools.common.sftp.SftpFileAttributes
getAttributes
(SftpFile file) Deprecated, for removal: This API element is subject to removal in a future version.com.sshtools.common.sftp.SftpFileAttributes
getAttributes
(String path) Get the attributes of a file.protected com.sshtools.common.sftp.SftpFileAttributes
getAttributes
(String path, int messageId) byte[]
Returns the canonical newline convention in use when reading/writing text files.Get the current encoding being used for filename Strings.Gets the users default directory.getExtendedReply
(com.sshtools.common.util.UnsignedInteger32 requestId) byte[]
getExtension
(String name) Get the data value of a supported SFTP extension.Utility method to obtain anSftpFile
instance for a given path.byte[]
byte[]
getHandleResponse
(com.sshtools.common.util.UnsignedInteger32 requestId) com.sshtools.common.sftp.SftpFileAttributes
getLinkAttributes
(String path) Get the attributes of a file.int
com.sshtools.common.util.UnsignedInteger32
protected int
int
com.sshtools.common.util.UnsignedInteger32
protected com.sshtools.common.util.UnsignedInteger32
protected com.sshtools.common.util.UnsignedInteger32
void
getOKRequestStatus
(com.sshtools.common.util.UnsignedInteger32 requestId) Verify that an OK status has been returned for a request id.getResponse
(com.sshtools.common.util.UnsignedInteger32 requestId) int
Version 4 of the SFTP protocol allows the server to return its maximum supported version instead of the actual version to be used.getSingleFileResponse
(SftpMessage bar, String messageName) Get a single SftpFile object from a message returning SSH_FXP_NAME result.getSymbolicLinkTarget
(String linkpath) Get the target path of a symbolic link.int
boolean
isClosed()
int
listChildren
(SftpFile file, List<SftpFile> children) Deprecated, for removal: This API element is subject to removal in a future version.void
lockFile
(byte[] handle, long offset, long length, int lockFlags) Deprecated, for removal: This API element is subject to removal in a future version.void
makeDirectory
(String path) Make a directory.void
makeDirectory
(String path, com.sshtools.common.sftp.SftpFileAttributes attrs) Make a directory.openDirectory
(String path) Open a directory.Open a file.Open a file.openFileVersion5
(String absolutePath, int flags, int accessFlags, com.sshtools.common.sftp.SftpFileAttributes attrs) void
performOptimizedRead
(String filename, byte[] handle, long length, int blocksize, OutputStream out, int outstandingRequests, FileTransferProgress progress) Deprecated, for removal: This API element is subject to removal in a future version.void
performOptimizedRead
(String filename, byte[] handle, long length, int blocksize, OutputStream out, int outstandingRequests, FileTransferProgress progress, long position) Deprecated, for removal: This API element is subject to removal in a future version.void
performOptimizedWrite
(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress) Deprecated.void
performOptimizedWrite
(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress, long position) Deprecated, for removal: This API element is subject to removal in a future version.void
performSynchronousRead
(byte[] handle, int blocksize, OutputStream out, FileTransferProgress progress, long position) Deprecated, for removal: This API element is subject to removal in a future version.com.sshtools.common.util.UnsignedInteger32
postReadRequest
(byte[] handle, long offset, int len) Deprecated, for removal: This API element is subject to removal in a future version.com.sshtools.common.util.UnsignedInteger32
postWriteRequest
(byte[] handle, long position, byte[] data, int off, int len) Deprecated, for removal: This API element is subject to removal in a future version.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) Deprecated, for removal: This API element is subject to removal in a future version.void
recurseMakeDirectory
(String path) Recurse through a hierarchy of directories creating them as necessary.void
removeDirectory
(String path) Remove an empty directory.void
removeFile
(String filename) Remove a file.void
renameFile
(String oldpath, String newpath) Rename an existing file.void
renameFile
(String oldpath, String newpath, int flags) com.sshtools.common.util.UnsignedInteger32
sendExtensionMessage
(String request, byte[] requestData) Send an extension message and return the response.void
setAttributes
(byte[] handle, com.sshtools.common.sftp.SftpFileAttributes attrs) Deprecated, for removal: This API element is subject to removal in a future version.void
setAttributes
(SftpFile path, com.sshtools.common.sftp.SftpFileAttributes attrs) Deprecated, for removal: This API element is subject to removal in a future version.void
setAttributes
(String path, com.sshtools.common.sftp.SftpFileAttributes attrs) Sets the attributes of a file.void
setCharsetEncoding
(String charset) Allows the default character encoding to be overriden for filename strings.boolean
supportsExtension
(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) Deprecated, for removal: This API element is subject to removal in a future version.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.Methods inherited from class com.sshtools.client.tasks.AbstractSubsystem
getConnection, nextMessage, onCloseSession, sendMessage
-
Field Details
-
OPEN_READ
public static final int OPEN_READFile open flag, opens the file for reading.- See Also:
-
OPEN_WRITE
public static final int OPEN_WRITEFile open flag, opens the file for writing.- See Also:
-
OPEN_APPEND
public static final int OPEN_APPENDFile open flag, forces all writes to append data at the end of the file.- See Also:
-
OPEN_CREATE
public static final int OPEN_CREATEFile open flag, if specified a new file will be created if one does not already exist.- See Also:
-
OPEN_TRUNCATE
public static final int OPEN_TRUNCATEFile open flag, forces an existing file with the same name to be truncated to zero length when creating a file by specifying OPEN_CREATE.- See Also:
-
OPEN_EXCLUSIVE
public static final int OPEN_EXCLUSIVEFile open flag, causes an open request to fail if the named file already exists. OPEN_CREATE must also be specified if this flag is used.- See Also:
-
OPEN_TEXT
public static final int OPEN_TEXTFile open flag, causes the file to be opened in text mode. This instructs the server to convert the text file to the canonical newline convention in use. Any files retrieved using this mode should then be converted from the canonical newline convention to that of the clients.- See Also:
-
SSH_FXP_STATUS
public static final int SSH_FXP_STATUS- See Also:
-
SSH_FXP_HANDLE
public static final int SSH_FXP_HANDLE- See Also:
-
SSH_FXP_DATA
public static final int SSH_FXP_DATA- See Also:
-
SSH_FXP_NAME
public static final int SSH_FXP_NAME- See Also:
-
SSH_FXP_ATTRS
public static final int SSH_FXP_ATTRS- See Also:
-
SSH_FXP_EXTENDED
public static final int SSH_FXP_EXTENDED- See Also:
-
SSH_FXP_EXTENDED_REPLY
public static final int SSH_FXP_EXTENDED_REPLY- See Also:
-
MAX_VERSION
public static final int MAX_VERSION- See Also:
-
SSH_FXF_ACCESS_DISPOSITION
public static final int SSH_FXF_ACCESS_DISPOSITIONVersion 5 new flags- See Also:
-
SSH_FXF_CREATE_NEW
public static final int SSH_FXF_CREATE_NEW- See Also:
-
SSH_FXF_CREATE_TRUNCATE
public static final int SSH_FXF_CREATE_TRUNCATE- See Also:
-
SSH_FXF_OPEN_EXISTING
public static final int SSH_FXF_OPEN_EXISTING- See Also:
-
SSH_FXF_OPEN_OR_CREATE
public static final int SSH_FXF_OPEN_OR_CREATE- See Also:
-
SSH_FXF_TRUNCATE_EXISTING
public static final int SSH_FXF_TRUNCATE_EXISTING- See Also:
-
SSH_FXF_ACCESS_APPEND_DATA
public static final int SSH_FXF_ACCESS_APPEND_DATA- See Also:
-
SSH_FXF_ACCESS_APPEND_DATA_ATOMIC
public static final int SSH_FXF_ACCESS_APPEND_DATA_ATOMIC- See Also:
-
SSH_FXF_ACCESS_TEXT_MODE
public static final int SSH_FXF_ACCESS_TEXT_MODE- See Also:
-
SSH_FXF_ACCESS_BLOCK_READ
public static final int SSH_FXF_ACCESS_BLOCK_READ- See Also:
-
SSH_FXF_ACCESS_BLOCK_WRITE
public static final int SSH_FXF_ACCESS_BLOCK_WRITE- See Also:
-
SSH_FXF_ACCESS_BLOCK_DELETE
public static final int SSH_FXF_ACCESS_BLOCK_DELETE- See Also:
-
SSH_FXF_ACCESS_BLOCK_ADVISORY
public static final int SSH_FXF_ACCESS_BLOCK_ADVISORY- See Also:
-
SSH_FXF_NOFOLLOW
public static final int SSH_FXF_NOFOLLOW- See Also:
-
SSH_FXF_DELETE_ON_CLOSE
public static final int SSH_FXF_DELETE_ON_CLOSE- See Also:
-
SSH_FXF_ACCESS_AUDIT_ALARM_INFO
public static final int SSH_FXF_ACCESS_AUDIT_ALARM_INFO- See Also:
-
SSH_FXF_ACCESS_BACKUP
public static final int SSH_FXF_ACCESS_BACKUP- See Also:
-
SSH_FXF_BACKUP_STREAM
public static final int SSH_FXF_BACKUP_STREAM- See Also:
-
SSH_FXF_OVERRIDE_OWNER
public static final int SSH_FXF_OVERRIDE_OWNER- See Also:
-
SSH_FXP_RENAME_OVERWRITE
public static final int SSH_FXP_RENAME_OVERWRITE- See Also:
-
SSH_FXP_RENAME_ATOMIC
public static final int SSH_FXP_RENAME_ATOMIC- See Also:
-
SSH_FXP_RENAME_NATIVE
public static final int SSH_FXP_RENAME_NATIVE- See Also:
-
-
Constructor Details
-
SftpChannel
public SftpChannel(com.sshtools.common.ssh.SshConnection con) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
-
Method Details
-
getVersion
public int getVersion() -
getMinimumWindowSize
protected com.sshtools.common.util.UnsignedInteger32 getMinimumWindowSize()- Specified by:
getMinimumWindowSize
in classAbstractSubsystem
-
getMaximumWindowSize
protected com.sshtools.common.util.UnsignedInteger32 getMaximumWindowSize()- Specified by:
getMaximumWindowSize
in classAbstractSubsystem
-
getMaximumPacketSize
protected int getMaximumPacketSize()- Specified by:
getMaximumPacketSize
in classAbstractSubsystem
-
getExtensions
-
getSession
- Overrides:
getSession
in classAbstractSubsystem
-
getCanonicalNewline
public byte[] getCanonicalNewline() throws com.sshtools.common.sftp.SftpStatusExceptionReturns the canonical newline convention in use when reading/writing text files.- Returns:
- String
- Throws:
com.sshtools.common.sftp.SftpStatusException
-
processSupported2
- Throws:
IOException
-
processSupported
- Throws:
IOException
-
setCharsetEncoding
public void setCharsetEncoding(String charset) throws com.sshtools.common.ssh.SshException, UnsupportedEncodingException Allows the default character encoding to be overriden for filename strings. This method should only be called once the channel has been initialized, if the version of the protocol is less than or equal to 3 the encoding is defaulted to latin1 as no encoding is specified by the protocol. If the version is greater than 3 the default encoding will be UTF-8.- Parameters:
charset
-- Throws:
UnsupportedEncodingException
com.sshtools.common.ssh.SshException
-
getServerVersion
public 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. This method returns the value provided by the server, if the servers version is less than or equal to 3 then this method will return the protocol number in use, otherwise it returns the maximum version supported by the server.- Returns:
- int
-
getCharsetEncoding
Get the current encoding being used for filename Strings.- Returns:
- String
-
supportsExtension
Does the server support an SFTP extension? This checks the extensions returned by the server during the SFTP version negotiation.- Parameters:
name
- String- Returns:
- boolean
-
getExtension
Get the data value of a supported SFTP extension. CallsupportsExtension(java.lang.String)
before calling this method to determine if the extension is available.- Parameters:
name
- String- Returns:
- String
-
close
public void close() -
getResponse
public SftpMessage getResponse(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.ssh.SshException
-
changePermissions
@Deprecated(since="3.1.0", forRemoval=true) public void changePermissions(byte[] file, int permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Change the permissions of a file.- Parameters:
file
- the filepermissions
- an integer value containing a file permissions mask- Throws:
com.sshtools.common.ssh.SshException
- ,SftpStatusExceptioncom.sshtools.common.sftp.SftpStatusException
- See Also:
-
}
-
changePermissions
@Deprecated(since="3.1.0", forRemoval=true) public void changePermissions(String filename, int permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Change the permissions of a file.- Parameters:
filename
- the path to the file.permissions
- an integer value containing a file permissions mask.- Throws:
com.sshtools.common.ssh.SshException
- ,SftpStatusExceptioncom.sshtools.common.sftp.SftpStatusException
- See Also:
-
changePermissions
public void changePermissions(byte[] handle, com.sshtools.common.sftp.PosixPermissions permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Change the permissions of a file.- Parameters:
handle
- the filepermissions
- permissions set.- Throws:
com.sshtools.common.ssh.SshException
- ,SftpStatusExceptioncom.sshtools.common.sftp.SftpStatusException
-
changePermissions
public void changePermissions(String filename, com.sshtools.common.sftp.PosixPermissions permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Change the permissions of a file.- Parameters:
filename
- the path to the file.permissions
- permissions set.- Throws:
com.sshtools.common.ssh.SshException
- ,SftpStatusExceptioncom.sshtools.common.sftp.SftpStatusException
-
changePermissions
public void changePermissions(String filename, String permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Change the permissions of a file.- Parameters:
filename
- the path to the file.permissions
- a string containing the permissions, for example "rw-r--r--"- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
getOKRequestStatus
public void getOKRequestStatus(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Verify that an OK status has been returned for a request id.- Parameters:
requestId
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
setAttributes
@Deprecated(since="3.1.0", forRemoval=true) public void setAttributes(SftpFile path, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Set the attributes of a file.- Parameters:
path
- the path to the fileattrs
- the file attributes- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
- See Also:
-
setAttributes
public void setAttributes(String path, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Sets the attributes of a file.- Parameters:
path
- the path to the file.attrs
- the file attributes.- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshException // * @deprecatedcom.sshtools.common.ssh.SshException
- See Also:
-
setAttributes
@Deprecated(since="3.1.0", forRemoval=true) public void setAttributes(byte[] handle, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Sets the attributes of a file.- Parameters:
handle
- the file object.attrs
- the new attributes.- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
- See Also:
-
SftpHandle#setAttributes(byte[], SftpFileAttributes)
-
postWriteRequest
@Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.util.UnsignedInteger32 postWriteRequest(byte[] handle, long position, byte[] data, int off, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Send a write request for an open file but do not wait for the response from the server.- Parameters:
handle
-position
-data
-off
-len
-- Returns:
- UnsignedInteger32
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
- See Also:
-
writeFile
public void writeFile(byte[] handle, com.sshtools.common.util.UnsignedInteger64 offset, byte[] data, int off, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Write a block of data to an open file.- Parameters:
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)- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
performOptimizedWrite
public void performOptimizedWrite(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated.Performs an optimized write of a file through asynchronous messaging and through buffering the local file into memory.- Parameters:
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.- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
TransferCancelledException
- See Also:
-
performOptimizedWrite
@Deprecated(since="3.1.0", forRemoval=true) public void performOptimizedWrite(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated, for removal: This API element is subject to removal in a future version.Performs an optimized write of a file through asynchronous messaging and through buffering the local file into memory.- Parameters:
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.- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
TransferCancelledException
- See Also:
-
performOptimizedRead
@Deprecated(since="3.1.0", forRemoval=true) public void performOptimizedRead(String filename, byte[] handle, long length, int blocksize, OutputStream out, int outstandingRequests, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated, for removal: This API element is subject to removal in a future version.Performs an optimized read of a file through use of asynchronous messages. The total number of outstanding read requests is configurable. This should be safe on file objects as the SSH protocol states that file read operations should return the exact number of bytes requested in each request. However the server is not required to return the exact number of bytes on device files and so this method should not be used for device files.- Parameters:
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
-- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
TransferCancelledException
- See Also:
-
performOptimizedRead
@Deprecated(since="3.1.0", forRemoval=true) public void performOptimizedRead(String filename, byte[] handle, long length, int blocksize, OutputStream out, int outstandingRequests, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated, for removal: This API element is subject to removal in a future version.Performs an optimized read of a file through use of asynchronous messages. The total number of outstanding read requests is configurable. This should be safe on file objects as the SSH protocol states that file read operations should return the exact number of bytes requested in each request. However the server is not required to return the exact number of bytes on device files and so this method should not be used for device files.- Parameters:
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 file- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
TransferCancelledException
- See Also:
-
performSynchronousRead
@Deprecated(since="3.1.0", forRemoval=true) public void performSynchronousRead(byte[] handle, int blocksize, OutputStream out, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException Deprecated, for removal: This API element is subject to removal in a future version.Perform a synchronous read of a file from the remote file system. This implementation waits for acknowledgement of every data packet before requesting additional data.- Parameters:
handle
-blocksize
-out
-progress
-position
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
TransferCancelledException
- See Also:
-
postReadRequest
@Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.util.UnsignedInteger32 postReadRequest(byte[] handle, long offset, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Post a read request to the server and return the request id; this is used to optimize file downloads. In normal operation the files are transfered by using a synchronous set of requests, however this slows the download as the client has to wait for the servers response before sending another request.- Parameters:
handle
-offset
-len
-- Returns:
- UnsignedInteger32
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
- See Also:
-
readFile
@Deprecated(since="3.1.0", forRemoval=true) public int readFile(byte[] handle, com.sshtools.common.util.UnsignedInteger64 offset, byte[] output, int off, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Read a block of data from an open file.- Parameters:
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- Returns:
- int
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
- See Also:
-
getFile
public SftpFile getFile(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Utility method to obtain anSftpFile
instance for a given path.- Parameters:
path
-- Returns:
- SftpFile
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getAbsolutePath
public String getAbsolutePath(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the absolute path of a file.- Parameters:
file
-- Returns:
- String
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
lockFile
@Deprecated(since="3.1.0", forRemoval=true) public void lockFile(byte[] handle, long offset, long length, int lockFlags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Lock file.- Parameters:
handle
-offset
-length
-lockFlags
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
- See Also:
-
unlockFile
@Deprecated(since="3.1.0", forRemoval=true) public void unlockFile(byte[] handle, long offset, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Lock file.- Parameters:
handle
-offset
-length
-lockFlags
-- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
- See Also:
-
createSymbolicLink
public void createSymbolicLink(String targetpath, String linkpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create a symbolic link.- Parameters:
targetpath
- the symbolic link to createlinkpath
- the path to which the symbolic link points- Throws:
com.sshtools.common.ssh.SshException
- if the remote SFTP version is < 3 an exception is thrown as this feature is not supported by previous versions of the protocol.com.sshtools.common.sftp.SftpStatusException
-
createLink
public void createLink(String targetpath, String linkpath, boolean symbolic) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Create a symbolic link.- Parameters:
targetpath
- the symbolic link to createlinkpath
- the path to which the symbolic link points- Throws:
com.sshtools.common.ssh.SshException
- if the remote SFTP version is < 3 an exception is thrown as this feature is not supported by previous versions of the protocol.com.sshtools.common.sftp.SftpStatusException
-
getSymbolicLinkTarget
public String getSymbolicLinkTarget(String linkpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the target path of a symbolic link.- Parameters:
linkpath
-- Returns:
- String
- Throws:
com.sshtools.common.ssh.SshException
- if the remote SFTP version is < 3 an exception is thrown as this feature is not supported by previous versions of the protocol.com.sshtools.common.sftp.SftpStatusException
-
getDefaultDirectory
public String getDefaultDirectory() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshExceptionGets the users default directory.- Returns:
- String
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
getAbsolutePath
public String getAbsolutePath(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the absolute path of a file.- Parameters:
path
-- Returns:
- String
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
getSingleFileResponse
public SftpFile getSingleFileResponse(SftpMessage bar, String messageName) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException Get a single SftpFile object from a message returning SSH_FXP_NAME result.- Parameters:
bar
-messageName
-- Returns:
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
listChildren
@Deprecated(since="3.1.0", forRemoval=true) public int listChildren(SftpFile file, List<SftpFile> children) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.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);
- Parameters:
file
-children
-- Returns:
- int
- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
- See Also:
-
recurseMakeDirectory
public void recurseMakeDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Recurse through a hierarchy of directories creating them as necessary.- Parameters:
path
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
openFile
public SftpHandle openFile(String absolutePath, int flags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Open a file.- Parameters:
absolutePath
-flags
-- Returns:
- SftpFile
- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
openFile
public SftpHandle openFile(String absolutePath, int flags, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Open a file.- Parameters:
absolutePath
-flags
-attrs
-- Returns:
- SftpFile
- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
openFileVersion5
public SftpHandle openFileVersion5(String absolutePath, int flags, int accessFlags, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
openDirectory
public SftpHandle openDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Open a directory.- Parameters:
path
-- Returns:
- sftpfile
- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
closeHandle
@Deprecated(since="3.1.0") public void closeHandle(byte[] handle) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated.- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
closeFile
Deprecated.Close a file or directory.- Parameters:
file
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptionIOException
-
removeDirectory
public void removeDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Remove an empty directory.- Parameters:
path
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
removeFile
public void removeFile(String filename) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Remove a file.- Parameters:
filename
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
renameFile
public void renameFile(String oldpath, String newpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Rename an existing file.- Parameters:
oldpath
-newpath
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
renameFile
public void renameFile(String oldpath, String newpath, int flags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getAttributes
public com.sshtools.common.sftp.SftpFileAttributes getAttributes(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the attributes of a file. This method follows symbolic links- Parameters:
path
-- Returns:
- SftpFileAttributes
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
getLinkAttributes
public com.sshtools.common.sftp.SftpFileAttributes getLinkAttributes(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Get the attributes of a file. This method does not follow symbolic links so will return the attributes of an actual link, not its target.- Parameters:
path
-- Returns:
- Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getAttributes
protected com.sshtools.common.sftp.SftpFileAttributes getAttributes(String path, int messageId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getAttributes
@Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.sftp.SftpFileAttributes getAttributes(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Deprecated, for removal: This API element is subject to removal in a future version.Get the attributes of a file.- Parameters:
file
-- Returns:
- SftpFileAttributes
- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
- See Also:
-
SftpHandle#setAttributes(byte[], SftpFileAttributes)
-
makeDirectory
public void makeDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Make a directory. If the directory exists this method will throw an exception.- Parameters:
path
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
makeDirectory
public void makeDirectory(String path, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException Make a directory. If the directory exists this method will throw an exception.- Parameters:
path
-attrs
-- Throws:
com.sshtools.common.sftp.SftpStatusException
- , SshExceptioncom.sshtools.common.ssh.SshException
-
getExtendedReply
public SftpMessage getExtendedReply(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getExtendedReply
public SftpMessage getExtendedReply(SftpMessage bar) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getHandleResponse
public byte[] getHandleResponse(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getHandle
public SftpHandle getHandle(com.sshtools.common.util.UnsignedInteger32 requestId, SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
getHandleResponse
public byte[] getHandleResponse(SftpMessage bar) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException - Throws:
com.sshtools.common.sftp.SftpStatusException
com.sshtools.common.ssh.SshException
-
sendExtensionMessage
public com.sshtools.common.util.UnsignedInteger32 sendExtensionMessage(String request, byte[] requestData) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException Send an extension message and return the response. This is for advanced use only.- Parameters:
request
- StringrequestData
- byte[]- Returns:
- SftpMessage
- Throws:
com.sshtools.common.ssh.SshException
com.sshtools.common.sftp.SftpStatusException
-
createPacket
Get a packet from the available pool or create if non available- Returns:
- Packet
- Throws:
IOException
-
isClosed
public boolean isClosed() -
getMaximumLocalWindowSize
public com.sshtools.common.util.UnsignedInteger32 getMaximumLocalWindowSize() -
getMaximumLocalPacketLength
public int getMaximumLocalPacketLength() -
getMaximumRemoteWindowSize
public com.sshtools.common.util.UnsignedInteger32 getMaximumRemoteWindowSize() -
getMaximumRemotePacketLength
public int getMaximumRemotePacketLength() -
getContext
-