public abstract class AbstractSftpClient extends AbstractSubsystemClient implements SftpClient, RawSftpClient
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenMode
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_WRITE_CHUNK_SIZE
Default value for "sftp-client-write-chunk-size"
|
static String |
WRITE_CHUNK_SIZE
Property used to avoid large buffers when
SftpClient.write(Handle, long, byte[], int, int) is invoked
with a large buffer size. |
log
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
BY_NAME_COMPARATOR, NAME_EXTRACTOR
Modifier | Constructor and Description |
---|---|
protected |
AbstractSftpClient() |
Modifier and Type | Method and Description |
---|---|
String |
canonicalPath(String path)
The effective "normalized" remote path
|
protected SftpClient.Attributes |
checkAttributes(int cmd,
org.apache.sshd.common.util.buffer.Buffer request) |
protected SftpClient.Attributes |
checkAttributesResponse(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected void |
checkCommandStatus(int cmd,
org.apache.sshd.common.util.buffer.Buffer request)
Sends the specified command, waits for the response and then invokes
checkResponseStatus(int, Buffer) |
protected int |
checkData(int cmd,
org.apache.sshd.common.util.buffer.Buffer request,
int dstOffset,
byte[] dst,
AtomicReference<Boolean> eofSignalled) |
protected int |
checkDataResponse(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer,
int dstoff,
byte[] dst,
AtomicReference<Boolean> eofSignalled) |
protected List<SftpClient.DirEntry> |
checkDirResponse(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer,
AtomicReference<Boolean> eolIndicator) |
protected byte[] |
checkHandle(int cmd,
org.apache.sshd.common.util.buffer.Buffer request) |
protected byte[] |
checkHandleResponse(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected String |
checkOneName(int cmd,
org.apache.sshd.common.util.buffer.Buffer request) |
protected String |
checkOneNameResponse(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected void |
checkResponseStatus(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer)
Checks if the incoming response is an
SSH_FXP_STATUS one,
and if so whether the substatus is SSH_FX_OK . |
protected void |
checkResponseStatus(int cmd,
int id,
int substatus,
String msg,
String lang) |
void |
close(SftpClient.Handle handle)
Close the handle obtained from one of the
open methods |
Channel |
getChannel() |
<E extends SftpClientExtension> |
getExtension(Class<? extends E> extensionType) |
protected SftpClientExtension |
getExtension(SftpClientExtensionFactory factory) |
SftpClientExtension |
getExtension(String extensionName) |
protected Map<String,Object> |
getParsedServerExtensions() |
protected Map<String,Object> |
getParsedServerExtensions(Map<String,byte[]> extensions) |
protected String |
getReferencedName(int cmd,
org.apache.sshd.common.util.buffer.Buffer buf,
int nameIndex) |
protected SftpClient.Attributes |
handleUnexpectedAttributesPacket(int cmd,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected byte[] |
handleUnexpectedHandlePacket(int cmd,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected IOException |
handleUnexpectedPacket(int cmd,
int expected,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected int |
handleUnknownDataPacket(int cmd,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected List<SftpClient.DirEntry> |
handleUnknownDirListingPacket(int cmd,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
protected String |
handleUnknownOneNamePacket(int cmd,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
void |
link(String linkPath,
String targetPath,
boolean symbolic)
Create a link
|
void |
lock(SftpClient.Handle handle,
long offset,
long length,
int mask) |
SftpClient.Attributes |
lstat(String path)
Retrieve remote path meta-data - do not follow symbolic links
|
void |
mkdir(String path)
Create remote directory
|
SftpClient.CloseableHandle |
open(String path,
Collection<SftpClient.OpenMode> options)
Opens a remote file with the specified mode(s)
|
SftpClient.CloseableHandle |
openDir(String path)
Obtain a handle for a directory
|
protected <B extends org.apache.sshd.common.util.buffer.Buffer> |
putReferencedName(int cmd,
B buf,
String name,
int nameIndex) |
int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst,
int dstOffset,
int len,
AtomicReference<Boolean> eofSignalled)
Reads data from the open (file) handle
|
protected SftpClient.Attributes |
readAttributes(int cmd,
org.apache.sshd.common.util.buffer.Buffer buffer,
AtomicInteger nameIndex) |
List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle,
AtomicReference<Boolean> eolIndicator) |
String |
readLink(String path)
Retrieve target of a link
|
void |
remove(String path) |
void |
rename(String oldPath,
String newPath,
Collection<SftpClient.CopyMode> options) |
void |
rmdir(String path)
Remove remote directory
|
void |
setStat(SftpClient.Handle handle,
SftpClient.Attributes attributes)
Update remote node meta-data
|
void |
setStat(String path,
SftpClient.Attributes attributes)
Update remote node meta-data
|
SftpClient.Attributes |
stat(SftpClient.Handle handle)
Retrieve file/directory handle meta-data
|
SftpClient.Attributes |
stat(String path)
Retrieve remote path meta-data - follow symbolic links if encountered
|
protected void |
throwStatusException(int cmd,
int id,
int substatus,
String msg,
String lang) |
void |
unlock(SftpClient.Handle handle,
long offset,
long length) |
protected void |
validateIncomingResponse(int cmd,
int id,
int type,
int length,
org.apache.sshd.common.util.buffer.Buffer buffer) |
void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src,
int srcOffset,
int len)
Write data to (open) file handle
|
protected <B extends org.apache.sshd.common.util.buffer.Buffer> |
writeAttributes(int cmd,
B buffer,
SftpClient.Attributes attributes) |
getSession, toString
getSimplifiedLogger
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getName, getNameDecodingCharset, getServerExtensions, getVersion, isClosing, listDir, open, open, openRemoteFileChannel, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, read, read, read, read, read, readDir, readDir, rename, rename, setNameDecodingCharset, symLink, write, write, write, write, write, write, write
getSession
getClientSession
findByName, getNameList, getNames, ofName, removeByName
getClientChannel
receive, send
public static final String WRITE_CHUNK_SIZE
SftpClient.write(Handle, long, byte[], int, int)
is invoked
with a large buffer size.public static final int DEFAULT_WRITE_CHUNK_SIZE
public Channel getChannel()
getChannel
in interface ClientChannelHolder
getChannel
in interface ChannelHolder
public <E extends SftpClientExtension> E getExtension(Class<? extends E> extensionType)
getExtension
in interface SftpClient
E
- The generic extension typeextensionType
- The extension typeOptionalFeature.isSupported()
- null
if
this extension type is not implemented by the clientSftpClient.getServerExtensions()
public SftpClientExtension getExtension(String extensionName)
getExtension
in interface SftpClient
extensionName
- The extension nameOptionalFeature.isSupported()
- null
if
this extension type is not implemented by the clientSftpClient.getServerExtensions()
protected SftpClientExtension getExtension(SftpClientExtensionFactory factory)
protected Map<String,Object> getParsedServerExtensions(Map<String,byte[]> extensions)
protected String getReferencedName(int cmd, org.apache.sshd.common.util.buffer.Buffer buf, int nameIndex)
cmd
- The command that was sent whose response contains the name to be decodedbuf
- The Buffer
containing the encoded namenameIndex
- The zero-based order of the requested names for the command - e.g.,
protected <B extends org.apache.sshd.common.util.buffer.Buffer> B putReferencedName(int cmd, B buf, String name, int nameIndex)
B
- Type of Buffer
being updatedcmd
- 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 linkprotected void checkCommandStatus(int cmd, org.apache.sshd.common.util.buffer.Buffer request) throws IOException
checkResponseStatus(int, Buffer)
cmd
- The command to sendrequest
- The request Buffer
IOException
- If failed to send, receive or check the returned statusRawSftpClient.send(int, Buffer)
,
RawSftpClient.receive(int)
,
checkResponseStatus(int, Buffer)
protected void checkResponseStatus(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
SSH_FXP_STATUS
one,
and if so whether the substatus is SSH_FX_OK
.cmd
- The sent command opcodebuffer
- The received response Buffer
IOException
- If response does not carry a status or carries
a bad status codecheckResponseStatus(int, int, int, String, String)
protected void checkResponseStatus(int cmd, int id, int substatus, String msg, String lang) throws IOException
cmd
- The sent command opcodeid
- The request idsubstatus
- The sub-status valuemsg
- The messagelang
- The languageIOException
- if the sub-status is not SSH_FX_OK
throwStatusException(int, int, int, String, String)
protected void throwStatusException(int cmd, int id, int substatus, String msg, String lang) throws IOException
IOException
protected byte[] checkHandle(int cmd, org.apache.sshd.common.util.buffer.Buffer request) throws IOException
cmd
- Command to be sentrequest
- The Buffer
containing the requestIOException
- If failed to send/receive or process the responseRawSftpClient.send(int, Buffer)
,
RawSftpClient.receive(int)
,
checkHandleResponse(int, Buffer)
protected byte[] checkHandleResponse(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected byte[] handleUnexpectedHandlePacket(int cmd, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected SftpClient.Attributes checkAttributes(int cmd, org.apache.sshd.common.util.buffer.Buffer request) throws IOException
cmd
- Command to be sentrequest
- Request Buffer
Attributes
IOException
- If failed to send/receive or process the responseRawSftpClient.send(int, Buffer)
,
RawSftpClient.receive(int)
,
checkAttributesResponse(int, Buffer)
protected SftpClient.Attributes checkAttributesResponse(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected SftpClient.Attributes handleUnexpectedAttributesPacket(int cmd, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected String checkOneName(int cmd, org.apache.sshd.common.util.buffer.Buffer request) throws IOException
cmd
- Command to be sentrequest
- The request Buffer
IOException
- If failed to send/receive or process the responseRawSftpClient.send(int, Buffer)
,
RawSftpClient.receive(int)
,
checkOneNameResponse(int, Buffer)
protected String checkOneNameResponse(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected String handleUnknownOneNamePacket(int cmd, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected SftpClient.Attributes readAttributes(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer, AtomicInteger nameIndex) throws IOException
IOException
protected <B extends org.apache.sshd.common.util.buffer.Buffer> B writeAttributes(int cmd, B buffer, SftpClient.Attributes attributes) throws IOException
IOException
public SftpClient.CloseableHandle open(String path, Collection<SftpClient.OpenMode> options) throws IOException
SftpClient
open
in interface SftpClient
path
- The remote pathoptions
- The desired mode - if none specified
then SftpClient.OpenMode.Read
is assumedSftpClient.CloseableHandle
IOException
- If failed to open the remote filepublic void close(SftpClient.Handle handle) throws IOException
SftpClient
open
methodsclose
in interface SftpClient
handle
- The Handle
to closeIOException
- If failed to executepublic void remove(String path) throws IOException
remove
in interface SftpClient
path
- The remote path to removeIOException
- If failed to executepublic void rename(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) throws IOException
rename
in interface SftpClient
IOException
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) throws IOException
SftpClient
read
in interface SftpClient
handle
- The file SftpClient.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 not null
then upon return holds a value indicating
whether EOF was reached due to the read. If null
indicator
value then this indication is not available-1
if EOF reachedIOException
- If failed to read the dataprotected int checkData(int cmd, org.apache.sshd.common.util.buffer.Buffer request, int dstOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException
IOException
protected int checkDataResponse(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer, int dstoff, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException
IOException
protected int handleUnknownDataPacket(int cmd, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws IOException
SftpClient
write
in interface SftpClient
handle
- The file SftpClient.Handle
fileOffset
- Zero-based offset to write in filesrc
- Data buffersrcOffset
- Offset of valid data in bufferlen
- Number of bytes to writeIOException
- If failed to write the datapublic void mkdir(String path) throws IOException
SftpClient
mkdir
in interface SftpClient
path
- Remote directory pathIOException
- If failed to executepublic void rmdir(String path) throws IOException
SftpClient
rmdir
in interface SftpClient
path
- Remote directory pathIOException
- If failed to executepublic SftpClient.CloseableHandle openDir(String path) throws IOException
SftpClient
openDir
in interface SftpClient
path
- Remote directory pathSftpClient.Handle
IOException
- If failed to executepublic List<SftpClient.DirEntry> readDir(SftpClient.Handle handle, AtomicReference<Boolean> eolIndicator) throws IOException
readDir
in interface SftpClient
handle
- Directory SftpClient.Handle
to read fromeolIndicator
- An indicator that can be used to get information
whether end of list has been reached - ignored if null
. Upon
return, set value indicates whether all entries have been exhausted - a null
value means that this information cannot be provided and another call to
readDir
is necessary in order to verify that no more entries are pendingList
of entries - null
to indicate no more entriesIOException
- If failed to access the remote siteprotected List<SftpClient.DirEntry> checkDirResponse(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer, AtomicReference<Boolean> eolIndicator) throws IOException
IOException
protected void validateIncomingResponse(int cmd, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected List<SftpClient.DirEntry> handleUnknownDirListingPacket(int cmd, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
IOException
protected IOException handleUnexpectedPacket(int cmd, int expected, int id, int type, int length, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
cmd
- The initial command sentexpected
- The expected packet typeid
- The reported identifiertype
- The reported SFTP response typelength
- The packet lengthbuffer
- The Buffer
after reading from it whatever data
led to this callnull
then implementor assumed
to handle the exception internal. Otherwise, the exception is re-thrownIOException
- If failed to handle the exception internallypublic String canonicalPath(String path) throws IOException
SftpClient
canonicalPath
in interface SftpClient
path
- The requested path - may be relative, and/or contain
dots - e.g., ".", "..", "./foo", "../bar"IOException
- If failed to executepublic SftpClient.Attributes stat(String path) throws IOException
SftpClient
stat
in interface SftpClient
path
- The remote pathSftpClient.Attributes
IOException
- If failed to executepublic SftpClient.Attributes lstat(String path) throws IOException
SftpClient
lstat
in interface SftpClient
path
- The remote pathSftpClient.Attributes
IOException
- If failed to executepublic SftpClient.Attributes stat(SftpClient.Handle handle) throws IOException
SftpClient
stat
in interface SftpClient
handle
- The SftpClient.Handle
obtained via one of the open
callsSftpClient.Attributes
IOException
- If failed to executepublic void setStat(String path, SftpClient.Attributes attributes) throws IOException
SftpClient
setStat
in interface SftpClient
path
- The remote pathattributes
- The SftpClient.Attributes
to updateIOException
- If failed to executepublic void setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws IOException
SftpClient
setStat
in interface SftpClient
handle
- The SftpClient.Handle
obtained via one of the open
callsattributes
- The SftpClient.Attributes
to updateIOException
- If failed to executepublic String readLink(String path) throws IOException
SftpClient
readLink
in interface SftpClient
path
- Remote path that represents a linkIOException
- If failed to executepublic void link(String linkPath, String targetPath, boolean symbolic) throws IOException
SftpClient
link
in interface SftpClient
linkPath
- The link locationtargetPath
- The referenced target by the linksymbolic
- If true
then make this a symbolic link, otherwise a hard oneIOException
- If failed to executepublic void lock(SftpClient.Handle handle, long offset, long length, int mask) throws IOException
lock
in interface SftpClient
IOException
public void unlock(SftpClient.Handle handle, long offset, long length) throws IOException
unlock
in interface SftpClient
IOException
Copyright © 2018–2019 The Apache Software Foundation. All rights reserved.