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 |
---|---|
private SftpClient.Attributes |
fileOpenAttributes |
private java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,java.lang.Object>> |
parsedExtensionsHolder |
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 |
---|---|
java.lang.String |
canonicalPath(java.lang.String path)
The effective "normalized" remote path
|
protected SftpClient.Attributes |
checkAttributes(int cmd,
Buffer request) |
protected SftpClient.Attributes |
checkAttributesResponse(int cmd,
Buffer buffer) |
protected void |
checkCommandStatus(int cmd,
Buffer request)
Sends the specified command, waits for the response and then invokes
checkResponseStatus(int, Buffer) |
protected int |
checkData(int cmd,
Buffer request,
int dstOffset,
byte[] dst,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) |
protected int |
checkDataResponse(int cmd,
Buffer buffer,
int dstoff,
byte[] dst,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) |
protected java.util.List<SftpClient.DirEntry> |
checkDirResponse(int cmd,
Buffer buffer,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) |
protected byte[] |
checkHandle(int cmd,
Buffer request) |
protected byte[] |
checkHandleResponse(int cmd,
Buffer buffer) |
protected java.lang.String |
checkOneName(int cmd,
Buffer request) |
protected java.lang.String |
checkOneNameResponse(int cmd,
Buffer buffer) |
protected void |
checkResponseStatus(int cmd,
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,
java.lang.String msg,
java.lang.String lang) |
void |
close(SftpClient.Handle handle)
Close the handle obtained from one of the
open methods |
Channel |
getChannel() |
<E extends SftpClientExtension> |
getExtension(java.lang.Class<? extends E> extensionType) |
protected SftpClientExtension |
getExtension(SftpClientExtensionFactory factory) |
SftpClientExtension |
getExtension(java.lang.String extensionName) |
protected java.util.Map<java.lang.String,java.lang.Object> |
getParsedServerExtensions() |
protected java.util.Map<java.lang.String,java.lang.Object> |
getParsedServerExtensions(java.util.Map<java.lang.String,byte[]> extensions) |
protected java.lang.String |
getReferencedName(int cmd,
Buffer buf,
int nameIndex) |
protected SftpClient.Attributes |
handleUnexpectedAttributesPacket(int cmd,
int id,
int type,
int length,
Buffer buffer) |
protected byte[] |
handleUnexpectedHandlePacket(int cmd,
int id,
int type,
int length,
Buffer buffer) |
protected java.io.IOException |
handleUnexpectedPacket(int cmd,
int expected,
int id,
int type,
int length,
Buffer buffer) |
protected int |
handleUnknownDataPacket(int cmd,
int id,
int type,
int length,
Buffer buffer) |
protected java.util.List<SftpClient.DirEntry> |
handleUnknownDirListingPacket(int cmd,
int id,
int type,
int length,
Buffer buffer) |
protected java.lang.String |
handleUnknownOneNamePacket(int cmd,
int id,
int type,
int length,
Buffer buffer) |
void |
link(java.lang.String linkPath,
java.lang.String targetPath,
boolean symbolic)
Create a link
|
void |
lock(SftpClient.Handle handle,
long offset,
long length,
int mask) |
SftpClient.Attributes |
lstat(java.lang.String path)
Retrieve remote path meta-data - do not follow symbolic links
|
void |
mkdir(java.lang.String path)
Create remote directory
|
SftpClient.CloseableHandle |
open(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> options)
Opens a remote file with the specified mode(s)
|
SftpClient.CloseableHandle |
openDir(java.lang.String path)
Obtain a handle for a directory
|
protected <B extends Buffer> |
putReferencedName(int cmd,
B buf,
java.lang.String name,
int nameIndex) |
int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst,
int dstOffset,
int len,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled)
Reads data from the open (file) handle
|
protected SftpClient.Attributes |
readAttributes(int cmd,
Buffer buffer,
java.util.concurrent.atomic.AtomicInteger nameIndex) |
java.util.List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) |
java.lang.String |
readLink(java.lang.String path)
Retrieve target of a link
|
void |
remove(java.lang.String path) |
void |
rename(java.lang.String oldPath,
java.lang.String newPath,
java.util.Collection<SftpClient.CopyMode> options) |
void |
rmdir(java.lang.String path)
Remove remote directory
|
void |
setStat(SftpClient.Handle handle,
SftpClient.Attributes attributes)
Update remote node meta-data
|
void |
setStat(java.lang.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(java.lang.String path)
Retrieve remote path meta-data - follow symbolic links if encountered
|
protected void |
throwStatusException(int cmd,
int id,
int substatus,
java.lang.String msg,
java.lang.String lang) |
void |
unlock(SftpClient.Handle handle,
long offset,
long length) |
void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src,
int srcOffset,
int len)
Write data to (open) file handle
|
protected <B extends 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
getClientChannel
getSession
getClientSession
findByName, getNameList, getNames, removeByName
receive, send
private final SftpClient.Attributes fileOpenAttributes
private final java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,java.lang.Object>> parsedExtensionsHolder
public Channel getChannel()
getChannel
in interface ChannelHolder
Channel
instancepublic <E extends SftpClientExtension> E getExtension(java.lang.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(java.lang.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 java.util.Map<java.lang.String,java.lang.Object> getParsedServerExtensions()
protected java.util.Map<java.lang.String,java.lang.Object> getParsedServerExtensions(java.util.Map<java.lang.String,byte[]> extensions)
protected java.lang.String getReferencedName(int cmd, 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 Buffer> B putReferencedName(int cmd, B buf, java.lang.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, Buffer request) throws java.io.IOException
checkResponseStatus(int, Buffer)
cmd
- The command to sendrequest
- The request Buffer
java.io.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, Buffer buffer) throws java.io.IOException
SSH_FXP_STATUS
one,
and if so whether the substatus is SSH_FX_OK
.cmd
- The sent command opcodebuffer
- The received response Buffer
java.io.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, java.lang.String msg, java.lang.String lang) throws java.io.IOException
cmd
- The sent command opcodeid
- The request idsubstatus
- The sub-status valuemsg
- The messagelang
- The languagejava.io.IOException
- if the sub-status is not SSH_FX_OK
throwStatusException(int, int, int, String, String)
protected void throwStatusException(int cmd, int id, int substatus, java.lang.String msg, java.lang.String lang) throws java.io.IOException
java.io.IOException
protected byte[] checkHandle(int cmd, Buffer request) throws java.io.IOException
cmd
- Command to be sentrequest
- The Buffer
containing the requestjava.io.IOException
- If failed to send/receive or process the responseRawSftpClient.send(int, Buffer)
,
RawSftpClient.receive(int)
,
checkHandleResponse(int, Buffer)
protected byte[] checkHandleResponse(int cmd, Buffer buffer) throws java.io.IOException
java.io.IOException
protected byte[] handleUnexpectedHandlePacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOException
protected SftpClient.Attributes checkAttributes(int cmd, Buffer request) throws java.io.IOException
cmd
- Command to be sentrequest
- Request Buffer
Attributes
java.io.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, Buffer buffer) throws java.io.IOException
java.io.IOException
protected SftpClient.Attributes handleUnexpectedAttributesPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOException
protected java.lang.String checkOneName(int cmd, Buffer request) throws java.io.IOException
cmd
- Command to be sentrequest
- The request Buffer
java.io.IOException
- If failed to send/receive or process the responseRawSftpClient.send(int, Buffer)
,
RawSftpClient.receive(int)
,
checkOneNameResponse(int, Buffer)
protected java.lang.String checkOneNameResponse(int cmd, Buffer buffer) throws java.io.IOException
java.io.IOException
protected java.lang.String handleUnknownOneNamePacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOException
protected SftpClient.Attributes readAttributes(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicInteger nameIndex) throws java.io.IOException
java.io.IOException
protected <B extends Buffer> B writeAttributes(int cmd, B buffer, SftpClient.Attributes attributes) throws java.io.IOException
java.io.IOException
public SftpClient.CloseableHandle open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options) throws java.io.IOException
SftpClient
open
in interface SftpClient
path
- The remote pathoptions
- The desired mode - if none specified
then SftpClient.OpenMode.Read
is assumedSftpClient.CloseableHandle
java.io.IOException
- If failed to open the remote filepublic void close(SftpClient.Handle handle) throws java.io.IOException
SftpClient
open
methodsclose
in interface SftpClient
handle
- The Handle
to closejava.io.IOException
- If failed to executepublic void remove(java.lang.String path) throws java.io.IOException
remove
in interface SftpClient
path
- The remote path to removejava.io.IOException
- If failed to executepublic void rename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options) throws java.io.IOException
rename
in interface SftpClient
java.io.IOException
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.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 reachedjava.io.IOException
- If failed to read the dataprotected int checkData(int cmd, Buffer request, int dstOffset, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.IOException
java.io.IOException
protected int checkDataResponse(int cmd, Buffer buffer, int dstoff, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.IOException
java.io.IOException
protected int handleUnknownDataPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOException
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws java.io.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 writejava.io.IOException
- If failed to write the datapublic void mkdir(java.lang.String path) throws java.io.IOException
SftpClient
mkdir
in interface SftpClient
path
- Remote directory pathjava.io.IOException
- If failed to executepublic void rmdir(java.lang.String path) throws java.io.IOException
SftpClient
rmdir
in interface SftpClient
path
- Remote directory pathjava.io.IOException
- If failed to executepublic SftpClient.CloseableHandle openDir(java.lang.String path) throws java.io.IOException
SftpClient
openDir
in interface SftpClient
path
- Remote directory pathSftpClient.Handle
java.io.IOException
- If failed to executepublic java.util.List<SftpClient.DirEntry> readDir(SftpClient.Handle handle, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) throws java.io.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 entriesjava.io.IOException
- If failed to access the remote siteprotected java.util.List<SftpClient.DirEntry> checkDirResponse(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) throws java.io.IOException
java.io.IOException
protected java.util.List<SftpClient.DirEntry> handleUnknownDirListingPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOException
protected java.io.IOException handleUnexpectedPacket(int cmd, int expected, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOException
public java.lang.String canonicalPath(java.lang.String path) throws java.io.IOException
SftpClient
canonicalPath
in interface SftpClient
path
- The requested path - may be relative, and/or contain
dots - e.g., ".", "..", "./foo", "../bar"java.io.IOException
- If failed to executepublic SftpClient.Attributes stat(java.lang.String path) throws java.io.IOException
SftpClient
stat
in interface SftpClient
path
- The remote pathSftpClient.Attributes
java.io.IOException
- If failed to executepublic SftpClient.Attributes lstat(java.lang.String path) throws java.io.IOException
SftpClient
lstat
in interface SftpClient
path
- The remote pathSftpClient.Attributes
java.io.IOException
- If failed to executepublic SftpClient.Attributes stat(SftpClient.Handle handle) throws java.io.IOException
SftpClient
stat
in interface SftpClient
handle
- The SftpClient.Handle
obtained via one of the open
callsSftpClient.Attributes
java.io.IOException
- If failed to executepublic void setStat(java.lang.String path, SftpClient.Attributes attributes) throws java.io.IOException
SftpClient
setStat
in interface SftpClient
path
- The remote pathattributes
- The SftpClient.Attributes
to updatejava.io.IOException
- If failed to executepublic void setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws java.io.IOException
SftpClient
setStat
in interface SftpClient
handle
- The SftpClient.Handle
obtained via one of the open
callsattributes
- The SftpClient.Attributes
to updatejava.io.IOException
- If failed to executepublic java.lang.String readLink(java.lang.String path) throws java.io.IOException
SftpClient
readLink
in interface SftpClient
path
- Remote path that represents a linkjava.io.IOException
- If failed to executepublic void link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic) throws java.io.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 onejava.io.IOException
- If failed to executepublic void lock(SftpClient.Handle handle, long offset, long length, int mask) throws java.io.IOException
lock
in interface SftpClient
java.io.IOException
public void unlock(SftpClient.Handle handle, long offset, long length) throws java.io.IOException
unlock
in interface SftpClient
java.io.IOException