Class DefaultSftpClient
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.client.subsystem.AbstractSubsystemClient
-
- org.apache.sshd.client.subsystem.sftp.impl.AbstractSftpClient
-
- org.apache.sshd.client.subsystem.sftp.impl.DefaultSftpClient
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,ClientChannelHolder,ClientSessionHolder,RawSftpClient,SftpClient,SubsystemClient,ChannelHolder,NamedResource,SessionContextHolder,SessionHolder<ClientSession>
public class DefaultSftpClient extends AbstractSftpClient
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.sshd.client.subsystem.sftp.SftpClient
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenMode
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelSubsystemchannelprivate ClientSessionclientSessionprivate java.util.concurrent.atomic.AtomicBooleanclosingprivate java.util.concurrent.atomic.AtomicIntegercmdIdprivate java.util.NavigableMap<java.lang.String,byte[]>exposedExtensionsprivate java.util.NavigableMap<java.lang.String,byte[]>extensionsprivate java.util.Map<java.lang.Integer,Buffer>messagesprivate java.nio.charset.CharsetnameDecodingCharsetprivate BufferreceiveBufferprivate java.util.concurrent.atomic.AtomicIntegerversionHolderprivate byte[]workBuf-
Fields inherited from class org.apache.sshd.client.subsystem.sftp.impl.AbstractSftpClient
DEFAULT_WRITE_CHUNK_SIZE, WRITE_CHUNK_SIZE
-
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.client.subsystem.sftp.SftpClient
DEFAULT_CHANNEL_MODES, DEFAULT_CHANNEL_OPEN_TIMEOUT, DEFAULT_NAME_DECODING_CHARSET, DEFAULT_READ_BUFFER_SIZE, DEFAULT_WAIT_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, EMPTY_DIR_ENTRIES, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE, NAME_DECODING_CHARSET, SFTP_CHANNEL_OPEN_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description DefaultSftpClient(ClientSession clientSession)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected intdata(byte[] buf, int start, int len)Receive binary dataClientChannelgetClientChannel()ClientSessiongetClientSession()java.nio.charset.CharsetgetNameDecodingCharset()java.util.NavigableMap<java.lang.String,byte[]>getServerExtensions()intgetVersion()protected voidinit(long initializationTimeout)booleanisClosing()booleanisOpen()intnegotiateVersion(SftpVersionSelector selector)protected voidprocess(Buffer incoming)Process an SFTP packetprotected Bufferread()Bufferreceive(int id)protected booleanreceive(Buffer incoming)Read SFTP packets from bufferintsend(int cmd, Buffer buffer)voidsetNameDecodingCharset(java.nio.charset.Charset nameDecodingCharset)-
Methods inherited from class org.apache.sshd.client.subsystem.sftp.impl.AbstractSftpClient
canonicalPath, checkAttributes, checkAttributesResponse, checkCommandStatus, checkData, checkDataResponse, checkDirResponse, checkHandle, checkHandleResponse, checkOneName, checkOneNameResponse, checkResponseStatus, checkResponseStatus, close, getChannel, getExtension, getExtension, getExtension, getParsedServerExtensions, getParsedServerExtensions, getReferencedName, handleUnexpectedAttributesPacket, handleUnexpectedHandlePacket, handleUnexpectedPacket, handleUnknownDataPacket, handleUnknownDirListingPacket, handleUnknownOneNamePacket, link, lock, lstat, mkdir, open, openDir, putReferencedName, read, readAttributes, readDir, readLink, remove, rename, rmdir, setStat, setStat, stat, stat, throwStatusException, unlock, validateIncomingResponse, write, writeAttributes
-
Methods inherited from class org.apache.sshd.client.subsystem.AbstractSubsystemClient
toString
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
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.client.subsystem.sftp.SftpClient
getName, listDir, open, open, openRemoteFileChannel, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, read, read, read, read, read, readDir, readDir, rename, rename, symLink, write, write, write, write, write, write, write
-
Methods inherited from interface org.apache.sshd.client.subsystem.SubsystemClient
getSession
-
-
-
-
Field Detail
-
clientSession
private final ClientSession clientSession
-
channel
private final ChannelSubsystem channel
-
messages
private final java.util.Map<java.lang.Integer,Buffer> messages
-
cmdId
private final java.util.concurrent.atomic.AtomicInteger cmdId
-
receiveBuffer
private final Buffer receiveBuffer
-
workBuf
private final byte[] workBuf
-
versionHolder
private final java.util.concurrent.atomic.AtomicInteger versionHolder
-
closing
private final java.util.concurrent.atomic.AtomicBoolean closing
-
extensions
private final java.util.NavigableMap<java.lang.String,byte[]> extensions
-
exposedExtensions
private final java.util.NavigableMap<java.lang.String,byte[]> exposedExtensions
-
nameDecodingCharset
private java.nio.charset.Charset nameDecodingCharset
-
-
Constructor Detail
-
DefaultSftpClient
public DefaultSftpClient(ClientSession clientSession) throws java.io.IOException
- Throws:
java.io.IOException
-
-
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:
SftpClient.NAME_DECODING_CHARSET
-
setNameDecodingCharset
public void setNameDecodingCharset(java.nio.charset.Charset nameDecodingCharset)
-
isClosing
public boolean isClosing()
-
isOpen
public boolean isOpen()
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
data
protected int data(byte[] buf, int start, int len) throws java.io.IOExceptionReceive binary data- Parameters:
buf- The buffer for the incoming datastart- Offset in buffer to place the datalen- Available space in buffer for the data- Returns:
- Actual size of received data
- Throws:
java.io.IOException- If failed to receive incoming data
-
receive
protected boolean receive(Buffer incoming) throws java.io.IOException
Read SFTP packets from buffer- Parameters:
incoming- The receivedBuffer- Returns:
trueif data from incoming buffer was processed- Throws:
java.io.IOException- if failed to process the buffer- See Also:
process(Buffer)
-
process
protected void process(Buffer incoming) throws java.io.IOException
Process an SFTP packet- Parameters:
incoming- The receivedBuffer- Throws:
java.io.IOException- if failed to process the buffer
-
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
-
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
-
read
protected Buffer read() throws java.io.IOException
- Throws:
java.io.IOException
-
init
protected void init(long initializationTimeout) throws java.io.IOException- Throws:
java.io.IOException
-
negotiateVersion
public int negotiateVersion(SftpVersionSelector selector) throws java.io.IOException
- Parameters:
selector- TheSftpVersionSelectorto use - ignored ifnull- Returns:
- The selected version (may be same as current)
- Throws:
java.io.IOException- If failed to negotiate
-
-