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 intstatic final intFile open flag, forces all writes to append data at the end of the file.static final intFile open flag, if specified a new file will be created if one does not already exist.static final intFile open flag, causes an open request to fail if the named file already exists.static final intFile open flag, opens the file for reading.static final intFile open flag, causes the file to be opened in text mode.static final intFile 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 intFile open flag, opens the file for writing.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intVersion 5 new flagsstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class com.sshtools.client.tasks.AbstractSubsystem
con, session, timeout -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangePermissions(byte[] file, int permissions) Deprecated, for removal: This API element is subject to removal in a future version.voidchangePermissions(byte[] handle, PosixPermissions permissions) Change the permissions of a file.voidchangePermissions(String filename, int permissions) Deprecated, for removal: This API element is subject to removal in a future version.voidchangePermissions(String filename, PosixPermissions permissions) Change the permissions of a file.voidchangePermissions(String filename, String permissions) Change the permissions of a file.voidclose()voidcloseFile(SftpHandle file) Deprecated.voidcloseHandle(byte[] handle) Deprecated.voidcreateLink(String targetpath, String linkpath, boolean symbolic) Create a symbolic link.protected PacketGet a packet from the available pool or create if non availablevoidcreateSymbolicLink(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.getAttributes(SftpFile file) Deprecated, for removal: This API element is subject to removal in a future version.getAttributes(String path) Get the attributes of a file.protected SftpFileAttributesgetAttributes(String path, int messageId, String messageName) 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(SftpMessage bar, String path, com.sshtools.common.util.UnsignedInteger32 requestId) getExtendedReply(com.sshtools.common.util.UnsignedInteger32 requestId, String path) byte[]getExtension(String name) Get the data value of a supported SFTP extension.Utility method to obtain anSftpFileinstance for a given path.byte[]getHandleResponse(SftpMessage bar, SftpFile file, com.sshtools.common.util.UnsignedInteger32 requestId) getLinkAttributes(String path) Get the attributes of a file.intcom.sshtools.common.util.UnsignedInteger32protected intintcom.sshtools.common.util.UnsignedInteger32protected com.sshtools.common.util.UnsignedInteger32protected com.sshtools.common.util.UnsignedInteger32voidgetOKRequestStatus(com.sshtools.common.util.UnsignedInteger32 requestId, String path) Verify that an OK status has been returned for a request id.getResponse(com.sshtools.common.util.UnsignedInteger32 requestId) intVersion 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, String path, com.sshtools.common.util.UnsignedInteger32 requestId) Get a single SftpFile object from a message returning SSH_FXP_NAME result.getSymbolicLinkTarget(String linkpath) Get the target path of a symbolic link.intbooleanisClosed()intlistChildren(SftpFile file, List<SftpFile> children) Deprecated, for removal: This API element is subject to removal in a future version.voidlockFile(byte[] handle, long offset, long length, int lockFlags) Deprecated, for removal: This API element is subject to removal in a future version.voidmakeDirectory(String path) Make a directory.voidmakeDirectory(String path, SftpFileAttributes attrs) Make a directory.openDirectory(String path) Open a directory.Open a file.openFile(String path, int flags, SftpFileAttributes attrs) Open a file.openFileVersion5(String path, int flags, int accessFlags, SftpFileAttributes attrs) voidperformOptimizedRead(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.voidperformOptimizedRead(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.voidperformOptimizedWrite(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress) Deprecated.voidperformOptimizedWrite(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.voidperformSynchronousRead(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.UnsignedInteger32postReadRequest(byte[] handle, long offset, int len) Deprecated, for removal: This API element is subject to removal in a future version.com.sshtools.common.util.UnsignedInteger32postWriteRequest(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 voidprocessSupported(byte[] data) protected voidprocessSupported2(byte[] data) intreadFile(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.voidrecurseMakeDirectory(String path) Recurse through a hierarchy of directories creating them as necessary.voidremoveDirectory(String path) Remove an empty directory.voidremoveFile(String path) Remove a file.voidrenameFile(String oldpath, String newpath) Rename an existing file.voidrenameFile(String oldpath, String newpath, int flags) com.sshtools.common.util.UnsignedInteger32sendExtensionMessage(String request, byte[] requestData) Send an extension message and return the response.voidsetAttributes(byte[] handle, SftpFileAttributes attrs) Deprecated, for removal: This API element is subject to removal in a future version.voidsetAttributes(SftpFile path, SftpFileAttributes attrs) Deprecated, for removal: This API element is subject to removal in a future version.voidsetAttributes(String path, SftpFileAttributes attrs) Sets the attributes of a file.voidsetCharsetEncoding(String charset) Allows the default character encoding to be overriden for filename strings.booleansupportsExtension(String name) Does the server support an SFTP extension? This checks the extensions returned by the server during the SFTP version negotiation.voidunlockFile(byte[] handle, long offset, long length) Deprecated, for removal: This API element is subject to removal in a future version.voidwriteFile(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
- Throws:
SshException
-
-
Method Details
-
getVersion
public int getVersion() -
getMinimumWindowSize
protected com.sshtools.common.util.UnsignedInteger32 getMinimumWindowSize()- Specified by:
getMinimumWindowSizein classAbstractSubsystem
-
getMaximumWindowSize
protected com.sshtools.common.util.UnsignedInteger32 getMaximumWindowSize()- Specified by:
getMaximumWindowSizein classAbstractSubsystem
-
getMaximumPacketSize
protected int getMaximumPacketSize()- Specified by:
getMaximumPacketSizein classAbstractSubsystem
-
getExtensions
-
getSession
- Overrides:
getSessionin classAbstractSubsystem
-
getCanonicalNewline
Returns the canonical newline convention in use when reading/writing text files.- Returns:
- String
- Throws:
SftpStatusException
-
processSupported2
- Throws:
IOException
-
processSupported
- Throws:
IOException
-
setCharsetEncoding
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:
UnsupportedEncodingExceptionSshException
-
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 SshException - Throws:
SshException
-
changePermissions
@Deprecated(since="3.1.0", forRemoval=true) public void changePermissions(byte[] file, int permissions) throws SftpStatusException, 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:
SshException- ,SftpStatusExceptionSftpStatusException- See Also:
-
}
-
changePermissions
@Deprecated(since="3.1.0", forRemoval=true) public void changePermissions(String filename, int permissions) throws SftpStatusException, 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:
SshException- ,SftpStatusExceptionSftpStatusException- See Also:
-
changePermissions
public void changePermissions(byte[] handle, PosixPermissions permissions) throws SftpStatusException, SshException Change the permissions of a file.- Parameters:
handle- the filepermissions- permissions set.- Throws:
SshException- ,SftpStatusExceptionSftpStatusException
-
changePermissions
public void changePermissions(String filename, PosixPermissions permissions) throws SftpStatusException, SshException Change the permissions of a file.- Parameters:
filename- the path to the file.permissions- permissions set.- Throws:
SshException- ,SftpStatusExceptionSftpStatusException
-
changePermissions
public void changePermissions(String filename, String permissions) throws SftpStatusException, 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:
SftpStatusException- , SshExceptionSshException
-
getOKRequestStatus
public void getOKRequestStatus(com.sshtools.common.util.UnsignedInteger32 requestId, String path) throws SftpStatusException, SshException Verify that an OK status has been returned for a request id.- Parameters:
requestId-- Throws:
SftpStatusException- , SshExceptionSshException
-
setAttributes
@Deprecated(since="3.1.0", forRemoval=true) public void setAttributes(SftpFile path, SftpFileAttributes attrs) throws SftpStatusException, 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:
SftpStatusExceptionSshException- See Also:
-
setAttributes
public void setAttributes(String path, SftpFileAttributes attrs) throws SftpStatusException, SshException Sets the attributes of a file.- Parameters:
path- the path to the file.attrs- the file attributes.- Throws:
SftpStatusException- , SshException // * @deprecatedSshException- See Also:
-
setAttributes
@Deprecated(since="3.1.0", forRemoval=true) public void setAttributes(byte[] handle, SftpFileAttributes attrs) throws SftpStatusException, 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:
SshExceptionSftpStatusException- 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 SftpStatusException, 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:
SshExceptionSftpStatusException- See Also:
-
writeFile
public void writeFile(byte[] handle, com.sshtools.common.util.UnsignedInteger64 offset, byte[] data, int off, int len) throws SftpStatusException, 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:
SshExceptionSftpStatusException
-
performOptimizedWrite
public void performOptimizedWrite(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress) throws SftpStatusException, 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:
SshExceptionSftpStatusExceptionTransferCancelledException- 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 SftpStatusException, 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:
SshExceptionSftpStatusExceptionTransferCancelledException- 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 SftpStatusException, 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:
SshExceptionSftpStatusExceptionTransferCancelledException- 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 SftpStatusException, 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:
SshExceptionSftpStatusExceptionTransferCancelledException- See Also:
-
performSynchronousRead
@Deprecated(since="3.1.0", forRemoval=true) public void performSynchronousRead(byte[] handle, int blocksize, OutputStream out, FileTransferProgress progress, long position) throws SftpStatusException, 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:
SftpStatusExceptionSshExceptionTransferCancelledException- See Also:
-
postReadRequest
@Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.util.UnsignedInteger32 postReadRequest(byte[] handle, long offset, int len) throws SftpStatusException, 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:
SshExceptionSftpStatusException- 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 SftpStatusException, 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:
SshExceptionSftpStatusException- See Also:
-
getFile
Utility method to obtain anSftpFileinstance for a given path.- Parameters:
path-- Returns:
- SftpFile
- Throws:
SftpStatusExceptionSshException
-
getAbsolutePath
Get the absolute path of a file.- Parameters:
file-- Returns:
- String
- Throws:
SshExceptionSftpStatusException
-
lockFile
@Deprecated(since="3.1.0", forRemoval=true) public void lockFile(byte[] handle, long offset, long length, int lockFlags) throws SftpStatusException, SshException Deprecated, for removal: This API element is subject to removal in a future version.Lock file.- Parameters:
handle-offset-length-lockFlags-- Throws:
SftpStatusExceptionSshException- See Also:
-
unlockFile
@Deprecated(since="3.1.0", forRemoval=true) public void unlockFile(byte[] handle, long offset, long length) throws SftpStatusException, SshException Deprecated, for removal: This API element is subject to removal in a future version.Lock file.- Parameters:
handle-offset-length-lockFlags-- Throws:
SftpStatusExceptionSshException- See Also:
-
createSymbolicLink
public void createSymbolicLink(String targetpath, String linkpath) throws SftpStatusException, SshException Create a symbolic link.- Parameters:
targetpath- the symbolic link to createlinkpath- the path to which the symbolic link points- Throws:
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
-
createLink
public void createLink(String targetpath, String linkpath, boolean symbolic) throws SftpStatusException, SshException Create a symbolic link.- Parameters:
targetpath- the symbolic link to createlinkpath- the path to which the symbolic link points- Throws:
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
-
getSymbolicLinkTarget
Get the target path of a symbolic link.- Parameters:
linkpath-- Returns:
- String
- Throws:
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
-
getDefaultDirectory
Gets the users default directory.- Returns:
- String
- Throws:
SshExceptionSftpStatusException
-
getAbsolutePath
Get the absolute path of a file.- Parameters:
path-- Returns:
- String
- Throws:
SshExceptionSftpStatusException
-
getSingleFileResponse
public SftpFile getSingleFileResponse(SftpMessage bar, String messageName, String path, com.sshtools.common.util.UnsignedInteger32 requestId) throws SshException, SftpStatusException Get a single SftpFile object from a message returning SSH_FXP_NAME result.- Parameters:
bar-messageName-- Returns:
- Throws:
SshExceptionSftpStatusException
-
listChildren
@Deprecated(since="3.1.0", forRemoval=true) public int listChildren(SftpFile file, List<SftpFile> children) throws SftpStatusException, 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:
SftpStatusException- , SshExceptionSshException- See Also:
-
recurseMakeDirectory
Recurse through a hierarchy of directories creating them as necessary.- Parameters:
path-- Throws:
SftpStatusException- , SshExceptionSshException
-
openFile
Open a file.- Parameters:
absolutePath-flags-- Returns:
- SftpFile
- Throws:
SftpStatusException- , SshExceptionSshException
-
openFile
public SftpHandle openFile(String path, int flags, SftpFileAttributes attrs) throws SftpStatusException, SshException Open a file.- Parameters:
path-flags-attrs-- Returns:
- SftpFile
- Throws:
SftpStatusException- , SshExceptionSshException
-
openFileVersion5
public SftpHandle openFileVersion5(String path, int flags, int accessFlags, SftpFileAttributes attrs) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
openDirectory
Open a directory.- Parameters:
path-- Returns:
- sftpfile
- Throws:
SftpStatusException- , SshExceptionSshException
-
closeHandle
@Deprecated(since="3.1.0") public void closeHandle(byte[] handle) throws SftpStatusException, SshException Deprecated.- Throws:
SftpStatusExceptionSshException
-
closeFile
Deprecated.Close a file or directory.- Parameters:
file-- Throws:
SftpStatusException- , SshExceptionIOException
-
removeDirectory
Remove an empty directory.- Parameters:
path-- Throws:
SftpStatusException- , SshExceptionSshException
-
removeFile
Remove a file.- Parameters:
path-- Throws:
SftpStatusException- , SshExceptionSshException
-
renameFile
Rename an existing file.- Parameters:
oldpath-newpath-- Throws:
SftpStatusException- , SshExceptionSshException
-
renameFile
public void renameFile(String oldpath, String newpath, int flags) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
getAttributes
Get the attributes of a file. This method follows symbolic links- Parameters:
path-- Returns:
- SftpFileAttributes
- Throws:
SshExceptionSftpStatusException
-
getLinkAttributes
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:
SftpStatusExceptionSshException
-
getAttributes
protected SftpFileAttributes getAttributes(String path, int messageId, String messageName) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
getAttributes
@Deprecated(since="3.1.0", forRemoval=true) public SftpFileAttributes getAttributes(SftpFile file) throws SftpStatusException, 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:
SftpStatusException- , SshExceptionSshException- See Also:
-
SftpHandle#setAttributes(byte[], SftpFileAttributes)
-
makeDirectory
Make a directory. If the directory exists this method will throw an exception.- Parameters:
path-- Throws:
SftpStatusException- , SshExceptionSshException
-
makeDirectory
public void makeDirectory(String path, SftpFileAttributes attrs) throws SftpStatusException, SshException Make a directory. If the directory exists this method will throw an exception.- Parameters:
path-attrs-- Throws:
SftpStatusException- , SshExceptionSshException
-
getExtendedReply
public SftpMessage getExtendedReply(com.sshtools.common.util.UnsignedInteger32 requestId, String path) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
getExtendedReply
public SftpMessage getExtendedReply(SftpMessage bar, String path, com.sshtools.common.util.UnsignedInteger32 requestId) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
getHandle
public SftpHandle getHandle(com.sshtools.common.util.UnsignedInteger32 requestId, SftpFile file) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
getHandleResponse
public byte[] getHandleResponse(SftpMessage bar, SftpFile file, com.sshtools.common.util.UnsignedInteger32 requestId) throws SftpStatusException, SshException - Throws:
SftpStatusExceptionSshException
-
sendExtensionMessage
public com.sshtools.common.util.UnsignedInteger32 sendExtensionMessage(String request, byte[] requestData) throws SshException, SftpStatusException Send an extension message and return the response. This is for advanced use only.- Parameters:
request- StringrequestData- byte[]- Returns:
- SftpMessage
- Throws:
SshExceptionSftpStatusException
-
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
-