public class DefaultSftpClient extends AbstractSftpClient
Modifier and Type | Class and Description |
---|---|
protected class |
DefaultSftpClient.SftpChannelSubsystem |
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenMode
Modifier and Type | Field and Description |
---|---|
private ChannelSubsystem |
channel |
private ClientSession |
clientSession |
private java.util.concurrent.atomic.AtomicBoolean |
closing |
private java.util.concurrent.atomic.AtomicInteger |
cmdId |
private java.util.NavigableMap<java.lang.String,byte[]> |
exposedExtensions |
private java.util.NavigableMap<java.lang.String,byte[]> |
extensions |
private java.util.Map<java.lang.Integer,Buffer> |
messages |
private java.nio.charset.Charset |
nameDecodingCharset |
private Buffer |
receiveBuffer |
private java.util.concurrent.atomic.AtomicInteger |
versionHolder |
INIT_COMMAND_SIZE
log
DEFAULT_CHANNEL_MODES, EMPTY_DIR_ENTRIES, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE
BY_NAME_COMPARATOR, NAME_EXTRACTOR
Constructor and Description |
---|
DefaultSftpClient(ClientSession clientSession,
SftpVersionSelector initialVersionSelector) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected ChannelSubsystem |
createSftpChannelSubsystem(ClientSession clientSession) |
protected int |
data(byte[] buf,
int start,
int len)
Receive binary data
|
ClientChannel |
getClientChannel() |
ClientSession |
getClientSession() |
java.nio.charset.Charset |
getNameDecodingCharset() |
java.util.NavigableMap<java.lang.String,byte[]> |
getServerExtensions() |
int |
getVersion() |
protected void |
handleInitResponse(Buffer buffer) |
protected void |
init(ClientSession session,
SftpVersionSelector initialVersionSelector,
java.time.Duration initializationTimeout) |
boolean |
isClosing() |
boolean |
isOpen() |
int |
negotiateVersion(SftpVersionSelector selector) |
protected void |
process(Buffer incoming)
Process an SFTP packet
|
protected boolean |
receive(Buffer incoming)
Read SFTP packets from buffer
|
Buffer |
receive(int id) |
Buffer |
receive(int id,
java.time.Duration idleTimeout) |
Buffer |
receive(int id,
long idleTimeout) |
int |
send(int cmd,
Buffer buffer) |
void |
setNameDecodingCharset(java.nio.charset.Charset nameDecodingCharset) |
protected Buffer |
waitForInitResponse(java.time.Duration initializationTimeout) |
canonicalPath, checkAttributes, checkAttributesResponse, checkCommandStatus, checkData, checkDataResponse, checkDirResponse, checkHandle, checkHandleResponse, checkOneName, checkOneNameResponse, checkResponseStatus, checkResponseStatus, close, getChannel, getExtension, getExtension, getParsedServerExtensions, getParsedServerExtensions, getReadBufferSize, getReferencedName, getWriteBufferSize, handleUnexpectedAttributesPacket, handleUnexpectedHandlePacket, handleUnexpectedPacket, handleUnknownDataPacket, handleUnknownDirListingPacket, handleUnknownOneNamePacket, link, listDir, lock, lstat, mkdir, open, openDir, openRemoteFileChannel, putReferencedName, read, read, read, readAttributes, readDir, readDir, readLink, remove, rename, rmdir, setStat, setStat, stat, stat, throwStatusException, unlock, validateIncomingResponse, write, write, write, writeAttributes
toString
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
singleSessionInstance
getExtension, getName, open, open, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, read, read, read, readDir, readEntries, rename, rename, singleSessionInstance, symLink, write, write, write, write, write
getSession
getSessionContext
findByName, findFirstMatchByName, getNameList, getNames, ofName, removeByName, safeCompareByName
private final ClientSession clientSession
private final ChannelSubsystem channel
private final java.util.Map<java.lang.Integer,Buffer> messages
private final java.util.concurrent.atomic.AtomicInteger cmdId
private final Buffer receiveBuffer
private final java.util.concurrent.atomic.AtomicInteger versionHolder
private final java.util.concurrent.atomic.AtomicBoolean closing
private final java.util.NavigableMap<java.lang.String,byte[]> extensions
private final java.util.NavigableMap<java.lang.String,byte[]> exposedExtensions
private java.nio.charset.Charset nameDecodingCharset
public DefaultSftpClient(ClientSession clientSession, SftpVersionSelector initialVersionSelector) throws java.io.IOException
clientSession
- The ClientSession
initialVersionSelector
- The initial SftpVersionSelector
- if null
then version 6 is
assumed.java.io.IOException
- If failed to initializepublic int getVersion()
public ClientSession getClientSession()
ClientSession
usedpublic ClientChannel getClientChannel()
ClientChannel
usedpublic java.util.NavigableMap<java.lang.String,byte[]> getServerExtensions()
NavigableMap
of the reported server extensions. where key=extension name (case
insensitive)public java.nio.charset.Charset getNameDecodingCharset()
null
) Charset
used to decode referenced files/folders namesSftpModuleProperties.NAME_DECODING_CHARSET
public void setNameDecodingCharset(java.nio.charset.Charset nameDecodingCharset)
public boolean isClosing()
public boolean isOpen()
public void close() throws java.io.IOException
java.io.IOException
protected int data(byte[] buf, int start, int len) throws java.io.IOException
buf
- The buffer for the incoming datastart
- Offset in buffer to place the datalen
- Available space in buffer for the datajava.io.IOException
- If failed to receive incoming dataprotected boolean receive(Buffer incoming) throws java.io.IOException
incoming
- The received Buffer
true
if data from incoming buffer was processedjava.io.IOException
- if failed to process the bufferprocess(Buffer)
protected void process(Buffer incoming) throws java.io.IOException
incoming
- The received Buffer
java.io.IOException
- if failed to process the bufferpublic int send(int cmd, Buffer buffer) throws java.io.IOException
cmd
- Command to send - Note: only lower 8-bits are usedbuffer
- The Buffer
containing the command datajava.io.IOException
- if failed to send commandpublic Buffer receive(int id) throws java.io.IOException
id
- The expected request idBuffer
containing the request idjava.io.IOException
- If connection closed or interruptedpublic Buffer receive(int id, long idleTimeout) throws java.io.IOException
id
- The expected request ididleTimeout
- The amount of time to wait for the responseBuffer
containing the request idjava.io.IOException
- If connection closed or interruptedpublic Buffer receive(int id, java.time.Duration idleTimeout) throws java.io.IOException
id
- The expected request ididleTimeout
- The amount of time to wait for the responseBuffer
containing the request idjava.io.IOException
- If connection closed or interruptedprotected void init(ClientSession session, SftpVersionSelector initialVersionSelector, java.time.Duration initializationTimeout) throws java.io.IOException
java.io.IOException
protected void handleInitResponse(Buffer buffer) throws java.io.IOException
java.io.IOException
protected Buffer waitForInitResponse(java.time.Duration initializationTimeout) throws java.io.IOException
java.io.IOException
public int negotiateVersion(SftpVersionSelector selector) throws java.io.IOException
selector
- The SftpVersionSelector
to use - ignored if null
java.io.IOException
- If failed to negotiateprotected ChannelSubsystem createSftpChannelSubsystem(ClientSession clientSession)