Package org.apache.sshd.sftp.client.impl
Class DefaultSftpClient
- 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.impl.DefaultSftpClient
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,ClientChannelHolder
,ClientSessionHolder
,SubsystemClient
,ChannelHolder
,NamedResource
,SessionContextHolder
,SessionHolder<ClientSession>
,FullAccessSftpClient
,RawSftpClient
,SftpClient
public class DefaultSftpClient extends AbstractSftpClient
- Author:
- Apache MINA SSHD Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DefaultSftpClient.SftpChannelSubsystem
-
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 inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
INIT_COMMAND_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.sftp.client.SftpClient
DEFAULT_CHANNEL_MODES, EMPTY_DIR_ENTRIES, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE
-
-
Constructor Summary
Constructors Constructor Description DefaultSftpClient(ClientSession clientSession, SftpVersionSelector initialVersionSelector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected ChannelSubsystem
createSftpChannelSubsystem(ClientSession clientSession)
protected int
data(byte[] buf, int start, int len)
Receive binary dataClientChannel
getClientChannel()
ClientSession
getClientSession()
Charset
getNameDecodingCharset()
NavigableMap<String,byte[]>
getServerExtensions()
int
getVersion()
protected void
handleInitResponse(Buffer buffer)
protected void
init(ClientSession session, SftpVersionSelector initialVersionSelector, Duration initializationTimeout)
boolean
isClosing()
boolean
isOpen()
int
negotiateVersion(SftpVersionSelector selector)
protected void
process(Buffer incoming)
Process an SFTP packetBuffer
receive(int id)
Buffer
receive(int id, long idleTimeout)
Buffer
receive(int id, Duration idleTimeout)
protected boolean
receive(Buffer incoming)
Read SFTP packets from bufferint
send(int cmd, Buffer buffer)
void
setNameDecodingCharset(Charset nameDecodingCharset)
protected Buffer
waitForInitResponse(Duration initializationTimeout)
-
Methods inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
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
-
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, read, read, read, read, read, read, read, readDir, readEntries, rename, rename, singleSessionInstance, symLink, write, write, write, write, write
-
Methods inherited from interface org.apache.sshd.client.subsystem.SubsystemClient
getSession
-
-
-
-
Constructor Detail
-
DefaultSftpClient
public DefaultSftpClient(ClientSession clientSession, SftpVersionSelector initialVersionSelector) throws IOException
- Parameters:
clientSession
- TheClientSession
initialVersionSelector
- The initialSftpVersionSelector
- ifnull
then version 6 is assumed.- Throws:
IOException
- If failed to initialize
-
-
Method Detail
-
getVersion
public int getVersion()
- Returns:
- The negotiated SFTP protocol version
-
getClientSession
public ClientSession getClientSession()
- Returns:
- The underlying
ClientSession
used
-
getClientChannel
public ClientChannel getClientChannel()
- Returns:
- The underlying
ClientChannel
used
-
getServerExtensions
public NavigableMap<String,byte[]> getServerExtensions()
- Returns:
- An (unmodifiable)
NavigableMap
of the reported server extensions. where key=extension name (case insensitive)
-
getNameDecodingCharset
public Charset getNameDecodingCharset()
- Returns:
- The (never
null
)Charset
used to decode referenced files/folders names - See Also:
SftpModuleProperties.NAME_DECODING_CHARSET
-
setNameDecodingCharset
public void setNameDecodingCharset(Charset nameDecodingCharset)
-
isClosing
public boolean isClosing()
-
isOpen
public boolean isOpen()
-
close
public void close() throws IOException
- Throws:
IOException
-
data
protected int data(byte[] buf, int start, int len) throws IOException
Receive 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:
IOException
- If failed to receive incoming data
-
receive
protected boolean receive(Buffer incoming) throws IOException
Read SFTP packets from buffer- Parameters:
incoming
- The receivedBuffer
- Returns:
true
if data from incoming buffer was processed- Throws:
IOException
- if failed to process the buffer- See Also:
process(Buffer)
-
process
protected void process(Buffer incoming) throws IOException
Process an SFTP packet- Parameters:
incoming
- The receivedBuffer
- Throws:
IOException
- if failed to process the buffer
-
send
public int send(int cmd, Buffer buffer) throws IOException
- Parameters:
cmd
- Command to send - Note: only lower 8-bits are usedbuffer
- TheBuffer
containing the command data- Returns:
- The assigned request id
- Throws:
IOException
- if failed to send command
-
receive
public Buffer receive(int id) throws IOException
- Parameters:
id
- The expected request id- Returns:
- The received response
Buffer
containing the request id - Throws:
IOException
- If connection closed or interrupted
-
receive
public Buffer receive(int id, long idleTimeout) throws IOException
- Parameters:
id
- The expected request ididleTimeout
- The amount of time to wait for the response- Returns:
- The received response
Buffer
containing the request id - Throws:
IOException
- If connection closed or interrupted
-
receive
public Buffer receive(int id, Duration idleTimeout) throws IOException
- Parameters:
id
- The expected request ididleTimeout
- The amount of time to wait for the response- Returns:
- The received response
Buffer
containing the request id - Throws:
IOException
- If connection closed or interrupted
-
init
protected void init(ClientSession session, SftpVersionSelector initialVersionSelector, Duration initializationTimeout) throws IOException
- Throws:
IOException
-
handleInitResponse
protected void handleInitResponse(Buffer buffer) throws IOException
- Throws:
IOException
-
waitForInitResponse
protected Buffer waitForInitResponse(Duration initializationTimeout) throws IOException
- Throws:
IOException
-
negotiateVersion
public int negotiateVersion(SftpVersionSelector selector) throws IOException
- Parameters:
selector
- TheSftpVersionSelector
to use - ignored ifnull
- Returns:
- The selected version (may be same as current)
- Throws:
IOException
- If failed to negotiate
-
createSftpChannelSubsystem
protected ChannelSubsystem createSftpChannelSubsystem(ClientSession clientSession)
-
-