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"
|
private SftpClient.Attributes |
fileOpenAttributes |
static int |
INIT_COMMAND_SIZE |
private java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,java.lang.Object>> |
parsedExtensionsHolder |
static java.lang.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. |
logDEFAULT_CHANNEL_MODES, DEFAULT_CHANNEL_OPEN_TIMEOUT, DEFAULT_NAME_DECODING_CHARSET, DEFAULT_WAIT_TIMEOUT, EMPTY_DIR_ENTRIES, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE, NAME_DECODING_CHARSET, SFTP_CHANNEL_OPEN_TIMEOUTBY_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 int |
getReadBufferSize() |
protected java.lang.String |
getReferencedName(int cmd,
Buffer buf,
int nameIndex) |
protected int |
getWriteBufferSize() |
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
|
java.lang.Iterable<SftpClient.DirEntry> |
listDir(SftpClient.Handle handle) |
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
|
java.nio.channels.FileChannel |
openRemoteFileChannel(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> modes)
Opens an
FileChannel on the specified remote path |
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
|
java.io.InputStream |
read(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> mode) |
java.io.InputStream |
read(java.lang.String path,
int bufferSize,
java.util.Collection<SftpClient.OpenMode> mode)
Read a remote file's data via an input stream
|
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.Iterable<SftpClient.DirEntry> |
readDir(java.lang.String path) |
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) |
protected void |
validateIncomingResponse(int cmd,
int id,
int type,
int length,
Buffer buffer) |
void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src,
int srcOffset,
int len)
Write data to (open) file handle
|
java.io.OutputStream |
write(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> mode) |
java.io.OutputStream |
write(java.lang.String path,
int bufferSize,
java.util.Collection<SftpClient.OpenMode> mode)
Write to a remote file via an output stream
|
protected <B extends Buffer> |
writeAttributes(int cmd,
B buffer,
SftpClient.Attributes attributes) |
toStringgetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getNameDecodingCharset, getServerExtensions, getVersion, isClosing, open, open, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, read, read, read, readDir, rename, rename, setNameDecodingCharset, symLink, write, write, write, write, writegetSessiongetSessionContextgetClientSessionfindByName, getNameList, getNames, ofName, removeByNamegetClientChannelreceive, receive, sendpublic static final int INIT_COMMAND_SIZE
public static final java.lang.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
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 ClientChannelHoldergetChannel in interface ChannelHolderChannel instancepublic <E extends SftpClientExtension> E getExtension(java.lang.Class<? extends E> extensionType)
getExtension in interface SftpClientE - 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 SftpClientextensionName - 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 Bufferjava.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 Bufferjava.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_OKthrowStatusException(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.IOExceptionprotected 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.IOExceptionprotected byte[] handleUnexpectedHandlePacket(int cmd,
int id,
int type,
int length,
Buffer buffer)
throws java.io.IOException
java.io.IOExceptionprotected SftpClient.Attributes checkAttributes(int cmd, Buffer request) throws java.io.IOException
cmd - Command to be sentrequest - Request BufferAttributesjava.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.IOExceptionprotected SftpClient.Attributes handleUnexpectedAttributesPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOExceptionprotected java.lang.String checkOneName(int cmd,
Buffer request)
throws java.io.IOException
cmd - Command to be sentrequest - The request Bufferjava.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.IOExceptionprotected java.lang.String handleUnknownOneNamePacket(int cmd,
int id,
int type,
int length,
Buffer buffer)
throws java.io.IOException
java.io.IOExceptionprotected SftpClient.Attributes readAttributes(int cmd, Buffer buffer, java.util.concurrent.atomic.AtomicInteger nameIndex) throws java.io.IOException
java.io.IOExceptionprotected <B extends Buffer> B writeAttributes(int cmd, B buffer, SftpClient.Attributes attributes) throws java.io.IOException
java.io.IOExceptionpublic SftpClient.CloseableHandle open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options) throws java.io.IOException
SftpClientopen in interface SftpClientpath - The remote pathoptions - The desired mode - if none specified then SftpClient.OpenMode.Read is assumedSftpClient.CloseableHandlejava.io.IOException - If failed to open the remote filepublic void close(SftpClient.Handle handle) throws java.io.IOException
SftpClientopen methodsclose in interface SftpClienthandle - The Handle to closejava.io.IOException - If failed to executepublic void remove(java.lang.String path)
throws java.io.IOException
remove in interface SftpClientpath - 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 SftpClientjava.io.IOExceptionpublic 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
SftpClientread in interface SftpClienthandle - 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.IOExceptionprotected 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.IOExceptionprotected int handleUnknownDataPacket(int cmd,
int id,
int type,
int length,
Buffer buffer)
throws java.io.IOException
java.io.IOExceptionpublic void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws java.io.IOException
SftpClientwrite in interface SftpClienthandle - The file SftpClient.HandlefileOffset - 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
SftpClientmkdir in interface SftpClientpath - Remote directory pathjava.io.IOException - If failed to executepublic void rmdir(java.lang.String path)
throws java.io.IOException
SftpClientrmdir in interface SftpClientpath - Remote directory pathjava.io.IOException - If failed to executepublic SftpClient.CloseableHandle openDir(java.lang.String path) throws java.io.IOException
SftpClientopenDir in interface SftpClientpath - Remote directory pathSftpClient.Handlejava.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 SftpClienthandle - 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.IOExceptionprotected void validateIncomingResponse(int cmd,
int id,
int type,
int length,
Buffer buffer)
throws java.io.IOException
java.io.IOExceptionprotected java.util.List<SftpClient.DirEntry> handleUnknownDirListingPacket(int cmd, int id, int type, int length, Buffer buffer) throws java.io.IOException
java.io.IOExceptionprotected java.io.IOException handleUnexpectedPacket(int cmd,
int expected,
int id,
int type,
int length,
Buffer buffer)
throws java.io.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-thrownjava.io.IOException - If failed to handle the exception internallypublic java.lang.String canonicalPath(java.lang.String path)
throws java.io.IOException
SftpClientcanonicalPath in interface SftpClientpath - 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
SftpClientstat in interface SftpClientpath - The remote pathSftpClient.Attributesjava.io.IOException - If failed to executepublic SftpClient.Attributes lstat(java.lang.String path) throws java.io.IOException
SftpClientlstat in interface SftpClientpath - The remote pathSftpClient.Attributesjava.io.IOException - If failed to executepublic SftpClient.Attributes stat(SftpClient.Handle handle) throws java.io.IOException
SftpClientstat in interface SftpClienthandle - The SftpClient.Handle obtained via one of the open callsSftpClient.Attributesjava.io.IOException - If failed to executepublic void setStat(java.lang.String path,
SftpClient.Attributes attributes)
throws java.io.IOException
SftpClientsetStat in interface SftpClientpath - 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
SftpClientsetStat in interface SftpClienthandle - 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
SftpClientreadLink in interface SftpClientpath - 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
SftpClientlink in interface SftpClientlinkPath - 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 SftpClientjava.io.IOExceptionpublic void unlock(SftpClient.Handle handle, long offset, long length) throws java.io.IOException
unlock in interface SftpClientjava.io.IOExceptionpublic java.lang.Iterable<SftpClient.DirEntry> readDir(java.lang.String path) throws java.io.IOException
readDir in interface SftpClientpath - The remote directory pathIterable that can be used to iterate over all the directory entries (unlike
SftpClient.readDir(Handle))java.io.IOException - If failed to access the remote siteSftpClient.readDir(Handle)public java.lang.Iterable<SftpClient.DirEntry> listDir(SftpClient.Handle handle) throws java.io.IOException
listDir in interface SftpClienthandle - A directory SftpClient.HandleIterable that can be used to iterate over all the directory entries (like
SftpClient.readDir(String)). Note: the iterable instance is not re-usable - i.e., files
can be iterated only oncejava.io.IOException - If failed to access the directorypublic java.nio.channels.FileChannel openRemoteFileChannel(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> modes)
throws java.io.IOException
SftpClientFileChannel on the specified remote pathopenRemoteFileChannel in interface SftpClientpath - The remote pathmodes - The access mode(s) - if null/empty then the SftpClient.DEFAULT_CHANNEL_MODES are usedFileChannel - Note: do not close this owner client instance until the
channel is no longer needed since it uses the client for providing the channel's
functionality.java.io.IOException - If failed to open the channelChannels.newInputStream(java.nio.channels.ReadableByteChannel),
Channels.newOutputStream(java.nio.channels.WritableByteChannel)public java.io.InputStream read(java.lang.String path,
int bufferSize,
java.util.Collection<SftpClient.OpenMode> mode)
throws java.io.IOException
SftpClientread in interface SftpClientpath - The remote file pathbufferSize - The internal read buffer sizemode - The remote file SftpClient.OpenModesInputStream for reading the remote file datajava.io.IOException - If failed to executepublic java.io.InputStream read(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> mode)
throws java.io.IOException
read in interface SftpClientjava.io.IOExceptionpublic java.io.OutputStream write(java.lang.String path,
int bufferSize,
java.util.Collection<SftpClient.OpenMode> mode)
throws java.io.IOException
SftpClientwrite in interface SftpClientpath - The remote file pathbufferSize - The internal write buffer sizemode - The remote file SftpClient.OpenModesOutputStream for writing the datajava.io.IOException - If failed to executepublic java.io.OutputStream write(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> mode)
throws java.io.IOException
write in interface SftpClientjava.io.IOExceptionprotected int getReadBufferSize()
protected int getWriteBufferSize()