Package org.apache.sshd.sftp.client.impl
Class AbstractSftpClient
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.client.subsystem.AbstractSubsystemClient
-
- org.apache.sshd.sftp.client.impl.AbstractSftpClient
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.Channel
,ClientChannelHolder
,ClientSessionHolder
,SubsystemClient
,ChannelHolder
,NamedResource
,SessionContextHolder
,SessionHolder<ClientSession>
,FullAccessSftpClient
,RawSftpClient
,SftpClient
,SftpErrorDataHandler
- Direct Known Subclasses:
DefaultSftpClient
,SftpFileSystem.Wrapper
public abstract class AbstractSftpClient extends AbstractSubsystemClient implements FullAccessSftpClient, SftpErrorDataHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.sshd.sftp.client.SftpClient
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenMode
-
-
Field Summary
Fields Modifier and Type Field Description protected SftpErrorDataHandler
errorDataHandler
private SftpClient.Attributes
fileOpenAttributes
static int
INIT_COMMAND_SIZE
private java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,java.lang.Object>>
parsedExtensionsHolder
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.NamedResource
BY_NAME_COMPARATOR, NAME_EXTRACTOR
-
Fields inherited from interface org.apache.sshd.sftp.client.SftpClient
DEFAULT_CHANNEL_MODES, EMPTY_DIR_ENTRIES, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE
-
Fields inherited from interface org.apache.sshd.sftp.client.SftpErrorDataHandler
EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSftpClient(SftpErrorDataHandler delegateHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
canonicalPath(java.lang.String path)
The effective "normalized" remote pathprotected SftpClient.Attributes
checkAttributes(int cmd, Buffer request)
protected SftpClient.Attributes
checkAttributesResponse(int cmd, Buffer buffer)
protected void
checkCommandStatus(int cmd, Buffer request)
Sends the specified command, waits for the response and then invokescheckResponseStatus(int, Buffer)
protected int
checkData(int cmd, Buffer request, int dstOffset, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled)
protected int
checkDataResponse(int cmd, Buffer buffer, int dstoff, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled)
protected java.util.List<SftpClient.DirEntry>
checkDirResponse(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator)
protected byte[]
checkHandle(int cmd, Buffer request)
protected byte[]
checkHandleResponse(int cmd, Buffer buffer)
protected java.lang.String
checkOneName(int cmd, Buffer request)
protected java.lang.String
checkOneNameResponse(int cmd, Buffer buffer)
protected void
checkResponseStatus(int cmd, int id, int substatus, java.lang.String msg, java.lang.String lang)
protected void
checkResponseStatus(int cmd, Buffer buffer)
Checks if the incoming response is anSSH_FXP_STATUS
one, and if so whether the substatus isSSH_FX_OK
.void
close(SftpClient.Handle handle)
Close the handle obtained from one of theopen
methodsvoid
errorData(byte[] buf, int start, int len)
Receive binary data from server error streamChannel
getChannel()
<E extends SftpClientExtension>
EgetExtension(java.lang.Class<? extends E> extensionType)
SftpClientExtension
getExtension(SftpClientExtensionFactory factory)
protected java.util.Map<java.lang.String,java.lang.Object>
getParsedServerExtensions()
protected java.util.Map<java.lang.String,java.lang.Object>
getParsedServerExtensions(java.util.Map<java.lang.String,byte[]> extensions)
protected int
getReadBufferSize()
protected java.lang.String
getReferencedName(int cmd, Buffer buf, int nameIndex)
protected int
getWriteBufferSize()
protected SftpClient.Attributes
handleUnexpectedAttributesPacket(int cmd, int id, int type, int length, Buffer buffer)
protected byte[]
handleUnexpectedHandlePacket(int cmd, int id, int type, int length, Buffer buffer)
protected java.io.IOException
handleUnexpectedPacket(int cmd, int expected, int id, int type, int length, Buffer buffer)
protected int
handleUnknownDataPacket(int cmd, int id, int type, int length, Buffer buffer)
protected java.util.List<SftpClient.DirEntry>
handleUnknownDirListingPacket(int cmd, int id, int type, int length, Buffer buffer)
protected java.lang.String
handleUnknownOneNamePacket(int cmd, int id, int type, int length, Buffer buffer)
void
link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic)
Create a linkjava.lang.Iterable<SftpClient.DirEntry>
listDir(SftpClient.Handle handle)
void
lock(SftpClient.Handle handle, long offset, long length, int mask)
SftpClient.Attributes
lstat(java.lang.String path)
Retrieve remote path meta-data - do not follow symbolic linksvoid
mkdir(java.lang.String path)
Create remote directorySftpClient.CloseableHandle
open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options)
Opens a remote file with the specified mode(s)SftpClient.CloseableHandle
openDir(java.lang.String path)
Obtain a handle for a directoryjava.nio.channels.FileChannel
openRemoteFileChannel(java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes)
Opens anFileChannel
on the specified remote pathprotected <B extends Buffer>
BputReferencedName(int cmd, B buf, java.lang.String name, int nameIndex)
java.io.InputStream
read(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode)
Read a remote file's data via an input streamint
read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled)
Reads data from the open (file) handleprotected SftpClient.Attributes
readAttributes(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicInteger nameIndex)
java.lang.Iterable<SftpClient.DirEntry>
readDir(java.lang.String path)
java.util.List<SftpClient.DirEntry>
readDir(SftpClient.Handle handle, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator)
java.lang.String
readLink(java.lang.String path)
Retrieve target of a linkvoid
remove(java.lang.String path)
void
rename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options)
void
rmdir(java.lang.String path)
Remove remote directoryvoid
setStat(java.lang.String path, SftpClient.Attributes attributes)
Update remote node meta-datavoid
setStat(SftpClient.Handle handle, SftpClient.Attributes attributes)
Update remote node meta-dataSftpClient.Attributes
stat(java.lang.String path)
Retrieve remote path meta-data - follow symbolic links if encounteredSftpClient.Attributes
stat(SftpClient.Handle handle)
Retrieve file/directory handle meta-dataprotected void
throwStatusException(int cmd, int id, int substatus, java.lang.String msg, java.lang.String lang)
void
unlock(SftpClient.Handle handle, long offset, long length)
protected void
validateIncomingResponse(int cmd, int id, int type, int length, Buffer buffer)
java.io.OutputStream
write(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode)
Write to a remote file via an output streamvoid
write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len)
Write data to (open) file handleprotected <B extends Buffer>
BwriteAttributes(int cmd, B buffer, SftpClient.Attributes attributes)
-
Methods inherited from class org.apache.sshd.client.subsystem.AbstractSubsystemClient
toString
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.client.channel.ClientChannelHolder
getClientChannel
-
Methods inherited from interface org.apache.sshd.client.session.ClientSessionHolder
getClientSession
-
Methods inherited from interface org.apache.sshd.sftp.client.RawSftpClient
receive, receive, receive, send
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
Methods inherited from interface org.apache.sshd.sftp.client.SftpClient
getExtension, getName, getNameDecodingCharset, getServerExtensions, getVersion, isClosing, open, open, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, read, read, read, read, readDir, readEntries, rename, rename, setNameDecodingCharset, singleSessionInstance, symLink, write, write, write, write, write, write
-
Methods inherited from interface org.apache.sshd.client.subsystem.SubsystemClient
getSession
-
-
-
-
Field Detail
-
INIT_COMMAND_SIZE
public static final int INIT_COMMAND_SIZE
- See Also:
- Constant Field Values
-
errorDataHandler
protected final SftpErrorDataHandler errorDataHandler
-
fileOpenAttributes
private final SftpClient.Attributes fileOpenAttributes
-
parsedExtensionsHolder
private final java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,java.lang.Object>> parsedExtensionsHolder
-
-
Constructor Detail
-
AbstractSftpClient
protected AbstractSftpClient(SftpErrorDataHandler delegateHandler)
-
-
Method Detail
-
getChannel
public Channel getChannel()
- Specified by:
getChannel
in interfaceChannelHolder
- Specified by:
getChannel
in interfaceClientChannelHolder
- Returns:
- The associated
Channel
instance
-
getExtension
public <E extends SftpClientExtension> E getExtension(java.lang.Class<? extends E> extensionType)
- Specified by:
getExtension
in interfaceSftpClient
- Type Parameters:
E
- The generic extension type- Parameters:
extensionType
- The extension type- Returns:
- The extension instance - Note: it is up to the caller to invoke
OptionalFeature.isSupported()
-null
if this extension type is not implemented by the client - See Also:
SftpClient.getServerExtensions()
-
getExtension
public SftpClientExtension getExtension(SftpClientExtensionFactory factory)
- Specified by:
getExtension
in interfaceSftpClient
- Parameters:
factory
- TheSftpClientExtensionFactory
instance to use - ignored ifnull
- Returns:
- The extension instance - Note: it is up to the caller to invoke
OptionalFeature.isSupported()
-null
if this extension type is not implemented by the client
-
getParsedServerExtensions
protected java.util.Map<java.lang.String,java.lang.Object> getParsedServerExtensions()
-
getParsedServerExtensions
protected java.util.Map<java.lang.String,java.lang.Object> getParsedServerExtensions(java.util.Map<java.lang.String,byte[]> extensions)
-
getReferencedName
protected java.lang.String getReferencedName(int cmd, Buffer buf, int nameIndex)
- Parameters:
cmd
- The command that was sent whose response contains the name to be decodedbuf
- TheBuffer
containing the encoded namenameIndex
- The zero-based order of the requested names for the command - e.g.,- When listing a directory's contents each successive name will have an increasing index.
- For SFTP version 3, when retrieving a single name, short name will have index=0 and the long one index=1.
- Returns:
- The decoded referenced name
-
putReferencedName
protected <B extends Buffer> B putReferencedName(int cmd, B buf, java.lang.String name, int nameIndex)
- Type Parameters:
B
- Type ofBuffer
being updated- Parameters:
cmd
- The command for which this name is being addedbuf
- The buffer instance to updatename
- The name to place in the buffernameIndex
- The zero-based order of the name for the specific command if more than one name required - e.g., rename, link/symbolic link- Returns:
- The updated buffer
-
checkCommandStatus
protected void checkCommandStatus(int cmd, Buffer request) throws java.io.IOException
Sends the specified command, waits for the response and then invokescheckResponseStatus(int, Buffer)
- Parameters:
cmd
- The command to sendrequest
- The requestBuffer
- Throws:
java.io.IOException
- If failed to send, receive or check the returned status- See Also:
RawSftpClient.send(int, Buffer)
,RawSftpClient.receive(int)
,checkResponseStatus(int, Buffer)
-
checkResponseStatus
protected void checkResponseStatus(int cmd, Buffer buffer) throws java.io.IOException
Checks if the incoming response is anSSH_FXP_STATUS
one, and if so whether the substatus isSSH_FX_OK
.- Parameters:
cmd
- The sent command opcodebuffer
- The received responseBuffer
- Throws:
java.io.IOException
- If response does not carry a status or carries a bad status code- See Also:
checkResponseStatus(int, int, int, String, String)
-
checkResponseStatus
protected void checkResponseStatus(int cmd, int id, int substatus, java.lang.String msg, java.lang.String lang) throws java.io.IOException
- Parameters:
cmd
- The sent command opcodeid
- The request idsubstatus
- The sub-status valuemsg
- The messagelang
- The language- Throws:
java.io.IOException
- if the sub-status is notSSH_FX_OK
- See Also:
throwStatusException(int, int, int, String, String)
-
throwStatusException
protected void throwStatusException(int cmd, int id, int substatus, java.lang.String msg, java.lang.String lang) throws java.io.IOException
- Throws:
java.io.IOException
-
checkHandle
protected byte[] checkHandle(int cmd, Buffer request) throws java.io.IOException
- Parameters:
cmd
- Command to be sentrequest
- TheBuffer
containing the request- Returns:
- The received handle identifier
- Throws:
java.io.IOException
- If failed to send/receive or process the response- See Also:
RawSftpClient.send(int, Buffer)
,RawSftpClient.receive(int)
,checkHandleResponse(int, Buffer)
-
checkHandleResponse
protected byte[] checkHandleResponse(int cmd, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnexpectedHandlePacket
protected byte[] handleUnexpectedHandlePacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
checkAttributes
protected SftpClient.Attributes checkAttributes(int cmd, Buffer request) throws java.io.IOException
- Parameters:
cmd
- Command to be sentrequest
- RequestBuffer
- Returns:
- The decoded response
Attributes
- Throws:
java.io.IOException
- If failed to send/receive or process the response- See Also:
RawSftpClient.send(int, Buffer)
,RawSftpClient.receive(int)
,checkAttributesResponse(int, Buffer)
-
checkAttributesResponse
protected SftpClient.Attributes checkAttributesResponse(int cmd, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnexpectedAttributesPacket
protected SftpClient.Attributes handleUnexpectedAttributesPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
checkOneName
protected java.lang.String checkOneName(int cmd, Buffer request) throws java.io.IOException
- Parameters:
cmd
- Command to be sentrequest
- The requestBuffer
- Returns:
- The retrieved name
- Throws:
java.io.IOException
- If failed to send/receive or process the response- See Also:
RawSftpClient.send(int, Buffer)
,RawSftpClient.receive(int)
,checkOneNameResponse(int, Buffer)
-
checkOneNameResponse
protected java.lang.String checkOneNameResponse(int cmd, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnknownOneNamePacket
protected java.lang.String handleUnknownOneNamePacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
readAttributes
protected SftpClient.Attributes readAttributes(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicInteger nameIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
writeAttributes
protected <B extends Buffer> B writeAttributes(int cmd, B buffer, SftpClient.Attributes attributes)
-
open
public SftpClient.CloseableHandle open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options) throws java.io.IOException
Description copied from interface:SftpClient
Opens a remote file with the specified mode(s)- Specified by:
open
in interfaceSftpClient
- Parameters:
path
- The remote pathoptions
- The desired mode - if none specified thenSftpClient.OpenMode.Read
is assumed- Returns:
- The file's
SftpClient.CloseableHandle
- Throws:
java.io.IOException
- If failed to open the remote file
-
close
public void close(SftpClient.Handle handle) throws java.io.IOException
Description copied from interface:SftpClient
Close the handle obtained from one of theopen
methods- Specified by:
close
in interfaceSftpClient
- Parameters:
handle
- TheHandle
to close- Throws:
java.io.IOException
- If failed to execute
-
remove
public void remove(java.lang.String path) throws java.io.IOException
- Specified by:
remove
in interfaceSftpClient
- Parameters:
path
- The remote path to remove- Throws:
java.io.IOException
- If failed to execute
-
rename
public void rename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options) throws java.io.IOException
- Specified by:
rename
in interfaceSftpClient
- Throws:
java.io.IOException
-
read
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.IOException
Description copied from interface:SftpClient
Reads data from the open (file) handle- Specified by:
read
in interfaceSftpClient
- Parameters:
handle
- The fileSftpClient.Handle
to read fromfileOffset
- The file offset to read fromdst
- The destination bufferdstOffset
- Offset in destination buffer to place the read datalen
- Available destination buffer size to readeofSignalled
- If notnull
then upon return holds a value indicating whether EOF was reached due to the read. Ifnull
indicator value then this indication is not available- Returns:
- Number of read bytes -
-1
if EOF reached - Throws:
java.io.IOException
- If failed to read the data- See Also:
- SFTP v6 - section 9.3
-
checkData
protected int checkData(int cmd, Buffer request, int dstOffset, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.IOException
- Throws:
java.io.IOException
-
checkDataResponse
protected int checkDataResponse(int cmd, Buffer buffer, int dstoff, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnknownDataPacket
protected int handleUnknownDataPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
errorData
public void errorData(byte[] buf, int start, int len) throws java.io.IOException
Description copied from interface:SftpErrorDataHandler
Receive binary data from server error stream- Specified by:
errorData
in interfaceSftpErrorDataHandler
- Parameters:
buf
- The buffer of the incoming datastart
- Offset in buffer to read the datalen
- Available data in buffer- Throws:
java.io.IOException
- If failed to receive incoming data
-
write
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws java.io.IOException
Description copied from interface:SftpClient
Write data to (open) file handle- Specified by:
write
in interfaceSftpClient
- Parameters:
handle
- The fileSftpClient.Handle
fileOffset
- Zero-based offset to write in filesrc
- Data buffersrcOffset
- Offset of valid data in bufferlen
- Number of bytes to write- Throws:
java.io.IOException
- If failed to write the data
-
mkdir
public void mkdir(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Create remote directory- Specified by:
mkdir
in interfaceSftpClient
- Parameters:
path
- Remote directory path- Throws:
java.io.IOException
- If failed to execute
-
rmdir
public void rmdir(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Remove remote directory- Specified by:
rmdir
in interfaceSftpClient
- Parameters:
path
- Remote directory path- Throws:
java.io.IOException
- If failed to execute
-
openDir
public SftpClient.CloseableHandle openDir(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Obtain a handle for a directory- Specified by:
openDir
in interfaceSftpClient
- Parameters:
path
- Remote directory path- Returns:
- The associated directory
SftpClient.Handle
- Throws:
java.io.IOException
- If failed to execute
-
readDir
public java.util.List<SftpClient.DirEntry> readDir(SftpClient.Handle handle, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) throws java.io.IOException
- Specified by:
readDir
in interfaceSftpClient
- Parameters:
handle
- DirectorySftpClient.Handle
to read fromeolIndicator
- An indicator that can be used to get information whether end of list has been reached - ignored ifnull
. Upon return, set value indicates whether all entries have been exhausted - anull
value means that this information cannot be provided and another call toreadDir
is necessary in order to verify that no more entries are pending- Returns:
- A
List
of entries -null
to indicate no more entries - Throws:
java.io.IOException
- If failed to access the remote site- See Also:
- SFTP v6 - section 9.4
-
checkDirResponse
protected java.util.List<SftpClient.DirEntry> checkDirResponse(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) throws java.io.IOException
- Throws:
java.io.IOException
-
validateIncomingResponse
protected void validateIncomingResponse(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnknownDirListingPacket
protected java.util.List<SftpClient.DirEntry> handleUnknownDirListingPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
handleUnexpectedPacket
protected java.io.IOException handleUnexpectedPacket(int cmd, int expected, int id, int type, int length, Buffer buffer) throws java.io.IOException
- Parameters:
cmd
- The initial command sentexpected
- The expected packet typeid
- The reported identifiertype
- The reported SFTP response typelength
- The packet lengthbuffer
- TheBuffer
after reading from it whatever data led to this call- Returns:
- The exception to throw - if
null
then implementor assumed to handle the exception internal. Otherwise, the exception is re-thrown - Throws:
java.io.IOException
- If failed to handle the exception internally
-
canonicalPath
public java.lang.String canonicalPath(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
The effective "normalized" remote path- Specified by:
canonicalPath
in interfaceSftpClient
- Parameters:
path
- The requested path - may be relative, and/or contain dots - e.g., ".", "..", "./foo", "../bar"- Returns:
- The effective "normalized" remote path
- Throws:
java.io.IOException
- If failed to execute
-
stat
public SftpClient.Attributes stat(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Retrieve remote path meta-data - follow symbolic links if encountered- Specified by:
stat
in interfaceSftpClient
- Parameters:
path
- The remote path- Returns:
- The associated
SftpClient.Attributes
- Throws:
java.io.IOException
- If failed to execute
-
lstat
public SftpClient.Attributes lstat(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Retrieve remote path meta-data - do not follow symbolic links- Specified by:
lstat
in interfaceSftpClient
- Parameters:
path
- The remote path- Returns:
- The associated
SftpClient.Attributes
- Throws:
java.io.IOException
- If failed to execute
-
stat
public SftpClient.Attributes stat(SftpClient.Handle handle) throws java.io.IOException
Description copied from interface:SftpClient
Retrieve file/directory handle meta-data- Specified by:
stat
in interfaceSftpClient
- Parameters:
handle
- TheSftpClient.Handle
obtained via one of theopen
calls- Returns:
- The associated
SftpClient.Attributes
- Throws:
java.io.IOException
- If failed to execute
-
setStat
public void setStat(java.lang.String path, SftpClient.Attributes attributes) throws java.io.IOException
Description copied from interface:SftpClient
Update remote node meta-data- Specified by:
setStat
in interfaceSftpClient
- Parameters:
path
- The remote pathattributes
- TheSftpClient.Attributes
to update- Throws:
java.io.IOException
- If failed to execute
-
setStat
public void setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws java.io.IOException
Description copied from interface:SftpClient
Update remote node meta-data- Specified by:
setStat
in interfaceSftpClient
- Parameters:
handle
- TheSftpClient.Handle
obtained via one of theopen
callsattributes
- TheSftpClient.Attributes
to update- Throws:
java.io.IOException
- If failed to execute
-
readLink
public java.lang.String readLink(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Retrieve target of a link- Specified by:
readLink
in interfaceSftpClient
- Parameters:
path
- Remote path that represents a link- Returns:
- The link target
- Throws:
java.io.IOException
- If failed to execute
-
link
public void link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic) throws java.io.IOException
Description copied from interface:SftpClient
Create a link- Specified by:
link
in interfaceSftpClient
- Parameters:
linkPath
- The link locationtargetPath
- The referenced target by the linksymbolic
- Iftrue
then make this a symbolic link, otherwise a hard one- Throws:
java.io.IOException
- If failed to execute
-
lock
public void lock(SftpClient.Handle handle, long offset, long length, int mask) throws java.io.IOException
- Specified by:
lock
in interfaceSftpClient
- Throws:
java.io.IOException
-
unlock
public void unlock(SftpClient.Handle handle, long offset, long length) throws java.io.IOException
- Specified by:
unlock
in interfaceSftpClient
- Throws:
java.io.IOException
-
readDir
public java.lang.Iterable<SftpClient.DirEntry> readDir(java.lang.String path) throws java.io.IOException
- Specified by:
readDir
in interfaceSftpClient
- Parameters:
path
- The remote directory path- Returns:
- An
Iterable
that can be used to iterate over all the directory entries (unlikeSftpClient.readDir(Handle)
) - Throws:
java.io.IOException
- If failed to access the remote site- See Also:
SftpClient.readDir(Handle)
-
listDir
public java.lang.Iterable<SftpClient.DirEntry> listDir(SftpClient.Handle handle) throws java.io.IOException
- Specified by:
listDir
in interfaceSftpClient
- Parameters:
handle
- A directorySftpClient.Handle
- Returns:
- An
Iterable
that can be used to iterate over all the directory entries (likeSftpClient.readDir(String)
). Note: the iterable instance is not re-usable - i.e., files can be iterated only once - Throws:
java.io.IOException
- If failed to access the directory
-
openRemoteFileChannel
public java.nio.channels.FileChannel openRemoteFileChannel(java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes) throws java.io.IOException
Description copied from interface:SftpClient
Opens anFileChannel
on the specified remote path- Specified by:
openRemoteFileChannel
in interfaceSftpClient
- Parameters:
path
- The remote pathmodes
- The access mode(s) - ifnull
/empty then theSftpClient.DEFAULT_CHANNEL_MODES
are used- Returns:
- The open
FileChannel
- Note: do not close this owner client instance until the channel is no longer needed since it uses the client for providing the channel's functionality. - Throws:
java.io.IOException
- If failed to open the channel- See Also:
Channels.newInputStream(java.nio.channels.ReadableByteChannel)
,Channels.newOutputStream(java.nio.channels.WritableByteChannel)
-
read
public java.io.InputStream read(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
Description copied from interface:SftpClient
Read a remote file's data via an input stream- Specified by:
read
in interfaceSftpClient
- Parameters:
path
- The remote file pathbufferSize
- The internal read buffer sizemode
- The remote fileSftpClient.OpenMode
s- Returns:
- An
InputStream
for reading the remote file data - Throws:
java.io.IOException
- If failed to execute
-
write
public java.io.OutputStream write(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
Description copied from interface:SftpClient
Write to a remote file via an output stream- Specified by:
write
in interfaceSftpClient
- Parameters:
path
- The remote file pathbufferSize
- The internal write buffer sizemode
- The remote fileSftpClient.OpenMode
s- Returns:
- An
OutputStream
for writing the data - Throws:
java.io.IOException
- If failed to execute
-
getReadBufferSize
protected int getReadBufferSize()
-
getWriteBufferSize
protected int getWriteBufferSize()
-
-