Package org.apache.sshd.sftp.client.fs
Class SftpFileSystem.Wrapper
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.client.subsystem.AbstractSubsystemClient
-
- org.apache.sshd.sftp.client.impl.AbstractSftpClient
-
- org.apache.sshd.sftp.client.fs.SftpFileSystem.Wrapper
-
- 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
- Enclosing class:
- SftpFileSystem
private final class SftpFileSystem.Wrapper extends AbstractSftpClient
-
-
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 private SftpClientdelegateprivate java.util.concurrent.atomic.AtomicBooleanopenprivate intreadSizeprivate intwriteSize-
Fields inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
errorDataHandler, INIT_COMMAND_SIZE, SFTP_CLIENT_CMD_TIMEOUT
-
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 privateWrapper(SftpClient delegate, SftpErrorDataHandler errorHandler, int readSize, int writeSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringcanonicalPath(java.lang.String path)The effective "normalized" remote pathvoidclose()voidclose(SftpClient.Handle handle)Close the handle obtained from one of theopenmethodsClientChannelgetClientChannel()ClientSessiongetClientSession()java.nio.charset.CharsetgetNameDecodingCharset()java.util.NavigableMap<java.lang.String,byte[]>getServerExtensions()intgetVersion()booleanisClosing()booleanisOpen()voidlink(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic)Create a linkjava.lang.Iterable<SftpClient.DirEntry>listDir(SftpClient.Handle handle)voidlock(SftpClient.Handle handle, long offset, long length, int mask)SftpClient.Attributeslstat(java.lang.String path)Retrieve remote path meta-data - do not follow symbolic linksvoidmkdir(java.lang.String path)Create remote directorySftpClient.CloseableHandleopen(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options)Opens a remote file with the specified mode(s)SftpClient.CloseableHandleopenDir(java.lang.String path)Obtain a handle for a directoryvoidput(java.io.InputStream stream, java.lang.String path)voidput(java.io.InputStream stream, java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes)voidput(java.io.InputStream stream, java.lang.String path, SftpClient.OpenMode... modes)voidput(java.nio.file.Path localFile, java.lang.String path)voidput(java.nio.file.Path localFile, java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes)voidput(java.nio.file.Path localFile, java.lang.String path, SftpClient.OpenMode... modes)java.io.InputStreamread(java.lang.String path)java.io.InputStreamread(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode)java.io.InputStreamread(java.lang.String path, SftpClient.OpenMode... mode)intread(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len)java.util.List<SftpClient.DirEntry>readDir(SftpClient.Handle handle)java.util.List<SftpClient.DirEntry>readDir(SftpClient.Handle handle, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator)java.lang.StringreadLink(java.lang.String path)Retrieve target of a linkBufferreceive(int id)Bufferreceive(int id, long timeout)Bufferreceive(int id, java.time.Duration timeout)voidremove(java.lang.String path)voidrename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options)voidrmdir(java.lang.String path)Remove remote directoryintsend(int cmd, Buffer buffer)voidsetNameDecodingCharset(java.nio.charset.Charset cs)voidsetStat(java.lang.String path, SftpClient.Attributes attributes)Update remote node meta-datavoidsetStat(SftpClient.Handle handle, SftpClient.Attributes attributes)Update remote node meta-dataSftpClient.Attributesstat(java.lang.String path)Retrieve remote path meta-data - follow symbolic links if encounteredSftpClient.Attributesstat(SftpClient.Handle handle)Retrieve file/directory handle meta-datavoidsymLink(java.lang.String linkPath, java.lang.String targetPath)Create symbolic linkvoidunlock(SftpClient.Handle handle, long offset, long length)SftpMessagewrite(int cmd, Buffer buffer)java.io.OutputStreamwrite(java.lang.String path)java.io.OutputStreamwrite(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode)java.io.OutputStreamwrite(java.lang.String path, SftpClient.OpenMode... mode)voidwrite(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len)Write data to (open) file handle-
Methods inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
checkAttributes, checkAttributesResponse, checkCommandStatus, checkDataResponse, checkDirResponse, checkHandle, checkHandleResponse, checkOneName, checkOneNameResponse, checkResponseStatus, checkResponseStatus, errorData, getChannel, getExtension, getExtension, getParsedServerExtensions, getParsedServerExtensions, getReadBufferSize, getReferencedName, getWriteBufferSize, handleUnexpectedAttributesPacket, handleUnexpectedHandlePacket, handleUnexpectedPacket, handleUnknownDataPacket, handleUnknownDirListingPacket, handleUnknownOneNamePacket, openRemoteFileChannel, put, putReferencedName, read, read, readAttributes, readDir, response, rpc, throwStatusException, write, writeAttributes
-
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.common.session.SessionHolder
getSessionContext
-
Methods inherited from interface org.apache.sshd.sftp.client.SftpClient
getExtension, getName, open, open, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, put, put, put, put, put, read, read, read, read, readEntries, rename, rename, singleSessionInstance, write, write, write
-
Methods inherited from interface org.apache.sshd.client.subsystem.SubsystemClient
getSession
-
-
-
-
Field Detail
-
delegate
private final SftpClient delegate
-
readSize
private final int readSize
-
writeSize
private final int writeSize
-
open
private final java.util.concurrent.atomic.AtomicBoolean open
-
-
Constructor Detail
-
Wrapper
private Wrapper(SftpClient delegate, SftpErrorDataHandler errorHandler, int readSize, int writeSize)
-
-
Method Detail
-
getVersion
public int getVersion()
- Returns:
- The negotiated SFTP protocol version
-
getClientSession
public ClientSession getClientSession()
- Returns:
- The underlying
ClientSessionused
-
getClientChannel
public ClientChannel getClientChannel()
- Returns:
- The underlying
ClientChannelused
-
getServerExtensions
public java.util.NavigableMap<java.lang.String,byte[]> getServerExtensions()
- Returns:
- An (unmodifiable)
NavigableMapof the reported server extensions. where key=extension name (case insensitive)
-
getNameDecodingCharset
public java.nio.charset.Charset getNameDecodingCharset()
- Returns:
- The (never
null)Charsetused to decode referenced files/folders names - See Also:
SftpModuleProperties.NAME_DECODING_CHARSET
-
setNameDecodingCharset
public void setNameDecodingCharset(java.nio.charset.Charset cs)
-
isClosing
public boolean isClosing()
-
isOpen
public boolean isOpen()
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
open
public SftpClient.CloseableHandle open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options) throws java.io.IOException
Description copied from interface:SftpClientOpens a remote file with the specified mode(s)- Specified by:
openin interfaceSftpClient- Overrides:
openin classAbstractSftpClient- Parameters:
path- The remote pathoptions- The desired mode - if none specified thenSftpClient.OpenMode.Readis 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:SftpClientClose the handle obtained from one of theopenmethods- Specified by:
closein interfaceSftpClient- Overrides:
closein classAbstractSftpClient- Parameters:
handle- TheHandleto close- Throws:
java.io.IOException- If failed to execute
-
remove
public void remove(java.lang.String path) throws java.io.IOException- Specified by:
removein interfaceSftpClient- Overrides:
removein classAbstractSftpClient- 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:
renamein interfaceSftpClient- Overrides:
renamein classAbstractSftpClient- Throws:
java.io.IOException
-
read
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws java.io.IOException
Description copied from interface:SftpClientWrite data to (open) file handle- Specified by:
writein interfaceSftpClient- Overrides:
writein classAbstractSftpClient- Parameters:
handle- The fileSftpClient.HandlefileOffset- 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.IOExceptionDescription copied from interface:SftpClientCreate remote directory- Specified by:
mkdirin interfaceSftpClient- Overrides:
mkdirin classAbstractSftpClient- Parameters:
path- Remote directory path- Throws:
java.io.IOException- If failed to execute
-
rmdir
public void rmdir(java.lang.String path) throws java.io.IOExceptionDescription copied from interface:SftpClientRemove remote directory- Specified by:
rmdirin interfaceSftpClient- Overrides:
rmdirin classAbstractSftpClient- 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:SftpClientObtain a handle for a directory- Specified by:
openDirin interfaceSftpClient- Overrides:
openDirin classAbstractSftpClient- 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) throws java.io.IOException
- Parameters:
handle- DirectorySftpClient.Handleto read from- Returns:
- A
Listof entries -nullto indicate no more entries Note: the list may be incomplete since the client and server have some internal imposed limit on the number of entries they can process. Therefore several calls to this method may be required (untilnull). In order to iterate over all the entries useSftpClient.readDir(String) - Throws:
java.io.IOException- If failed to access the remote site
-
listDir
public java.lang.Iterable<SftpClient.DirEntry> listDir(SftpClient.Handle handle) throws java.io.IOException
- Specified by:
listDirin interfaceSftpClient- Overrides:
listDirin classAbstractSftpClient- Parameters:
handle- A directorySftpClient.Handle- Returns:
- An
Iterablethat 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
-
canonicalPath
public java.lang.String canonicalPath(java.lang.String path) throws java.io.IOExceptionDescription copied from interface:SftpClientThe effective "normalized" remote path- Specified by:
canonicalPathin interfaceSftpClient- Overrides:
canonicalPathin classAbstractSftpClient- 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:SftpClientRetrieve remote path meta-data - follow symbolic links if encountered- Specified by:
statin interfaceSftpClient- Overrides:
statin classAbstractSftpClient- 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:SftpClientRetrieve remote path meta-data - do not follow symbolic links- Specified by:
lstatin interfaceSftpClient- Overrides:
lstatin classAbstractSftpClient- 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:SftpClientRetrieve file/directory handle meta-data- Specified by:
statin interfaceSftpClient- Overrides:
statin classAbstractSftpClient- Parameters:
handle- TheSftpClient.Handleobtained via one of theopencalls- 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.IOExceptionDescription copied from interface:SftpClientUpdate remote node meta-data- Specified by:
setStatin interfaceSftpClient- Overrides:
setStatin classAbstractSftpClient- Parameters:
path- The remote pathattributes- TheSftpClient.Attributesto 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:SftpClientUpdate remote node meta-data- Specified by:
setStatin interfaceSftpClient- Overrides:
setStatin classAbstractSftpClient- Parameters:
handle- TheSftpClient.Handleobtained via one of theopencallsattributes- TheSftpClient.Attributesto update- Throws:
java.io.IOException- If failed to execute
-
readLink
public java.lang.String readLink(java.lang.String path) throws java.io.IOExceptionDescription copied from interface:SftpClientRetrieve target of a link- Specified by:
readLinkin interfaceSftpClient- Overrides:
readLinkin classAbstractSftpClient- Parameters:
path- Remote path that represents a link- Returns:
- The link target
- Throws:
java.io.IOException- If failed to execute
-
symLink
public void symLink(java.lang.String linkPath, java.lang.String targetPath) throws java.io.IOExceptionDescription copied from interface:SftpClientCreate symbolic link- Parameters:
linkPath- The link locationtargetPath- The referenced target by the link- Throws:
java.io.IOException- If failed to execute- See Also:
SftpClient.link(String, String, boolean)
-
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:
readDirin interfaceSftpClient- Overrides:
readDirin classAbstractSftpClient- Parameters:
handle- DirectorySftpClient.Handleto 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 - anullvalue means that this information cannot be provided and another call toreadDiris necessary in order to verify that no more entries are pending- Returns:
- A
Listof entries -nullto indicate no more entries - Throws:
java.io.IOException- If failed to access the remote site- See Also:
- SFTP v6 - section 9.4
-
read
public java.io.InputStream read(java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
read
public java.io.InputStream read(java.lang.String path, SftpClient.OpenMode... mode) throws java.io.IOException- Throws:
java.io.IOException
-
read
public java.io.InputStream read(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException- Throws:
java.io.IOException
-
write
public java.io.OutputStream write(java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
write
public java.io.OutputStream write(java.lang.String path, SftpClient.OpenMode... mode) throws java.io.IOException- Throws:
java.io.IOException
-
write
public java.io.OutputStream write(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.nio.file.Path localFile, java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.io.InputStream stream, java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.nio.file.Path localFile, java.lang.String path, SftpClient.OpenMode... modes) throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.io.InputStream stream, java.lang.String path, SftpClient.OpenMode... modes) throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.nio.file.Path localFile, java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes) throws java.io.IOException- Throws:
java.io.IOException
-
put
public void put(java.io.InputStream stream, java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes) throws java.io.IOException- Throws:
java.io.IOException
-
link
public void link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic) throws java.io.IOExceptionDescription copied from interface:SftpClientCreate a link- Specified by:
linkin interfaceSftpClient- Overrides:
linkin classAbstractSftpClient- Parameters:
linkPath- The link locationtargetPath- The referenced target by the linksymbolic- Iftruethen 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:
lockin interfaceSftpClient- Overrides:
lockin classAbstractSftpClient- Throws:
java.io.IOException
-
unlock
public void unlock(SftpClient.Handle handle, long offset, long length) throws java.io.IOException
- Specified by:
unlockin interfaceSftpClient- Overrides:
unlockin classAbstractSftpClient- Throws:
java.io.IOException
-
send
public int send(int cmd, Buffer buffer) throws java.io.IOException- Parameters:
cmd- Command to send - Note: only lower 8-bits are usedbuffer- TheBuffercontaining the command data- Returns:
- The assigned request id
- Throws:
java.io.IOException- if failed to send command
-
write
public SftpMessage write(int cmd, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
receive
public Buffer receive(int id) throws java.io.IOException
- Parameters:
id- The expected request id- Returns:
- The received response
Buffercontaining the request id - Throws:
java.io.IOException- If connection closed or interrupted
-
receive
public Buffer receive(int id, long timeout) throws java.io.IOException
- Parameters:
id- The expected request idtimeout- The amount of time to wait for the response- Returns:
- The received response
Buffercontaining the request id - Throws:
java.io.IOException- If connection closed or interrupted
-
receive
public Buffer receive(int id, java.time.Duration timeout) throws java.io.IOException
- Parameters:
id- The expected request idtimeout- The amount of time to wait for the response- Returns:
- The received response
Buffercontaining the request id - Throws:
java.io.IOException- If connection closed or interrupted
-
-