public abstract class AbstractSftpClient extends AbstractSubsystemClient implements SftpClient, RawSftpClient
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenModelogDEFAULT_CHANNEL_MODES, DEFAULT_CHANNEL_OPEN_TIMEOUT, 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, SFTP_CHANNEL_OPEN_TIMEOUTBY_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,
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,
AtomicReference<Boolean> eofSignalled) |
protected int |
checkDataResponse(int cmd,
Buffer buffer,
int dstoff,
byte[] dst,
AtomicReference<Boolean> eofSignalled) |
protected List<SftpClient.DirEntry> |
checkDirResponse(int cmd,
Buffer buffer,
AtomicReference<Boolean> eolIndicator) |
protected byte[] |
checkHandle(int cmd,
Buffer request) |
protected byte[] |
checkHandleResponse(int cmd,
Buffer buffer) |
protected String |
checkOneName(int cmd,
Buffer request) |
protected 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,
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 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 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 List<SftpClient.DirEntry> |
handleUnknownDirListingPacket(int cmd,
int id,
int type,
int length,
Buffer buffer) |
protected String |
handleUnknownOneNamePacket(int cmd,
int id,
int type,
int length,
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
|
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(Buffer buffer) |
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) |
void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src,
int srcOffset,
int len)
Write data to (open) file handle
|
protected void |
writeAttributes(Buffer buffer,
SftpClient.Attributes attributes) |
getSession, toStringgetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getServerExtensions, getVersion, isClosing, listDir, open, open, openRemoteFileChannel, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, read, read, read, read, read, readDir, readDir, rename, rename, symLink, write, write, write, write, write, write, writegetClientChannelgetSessiongetClientSessionfindByName, getNameList, getNames, removeByNamereceive, sendpublic Channel getChannel()
getChannel in interface ChannelHolderChannel instancepublic <E extends SftpClientExtension> E getExtension(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(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 Map<String,Object> getParsedServerExtensions(Map<String,byte[]> extensions)
protected void checkCommandStatus(int cmd,
Buffer request)
throws IOException
checkResponseStatus(int, Buffer)cmd - The command to sendrequest - The request BufferIOException - 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 IOException
SSH_FXP_STATUS one,
and if so whether the substatus is SSH_FX_OK.cmd - The sent command opcodebuffer - The received response BufferIOException - 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_OKthrowStatusException(int, int, int, String, String)protected void throwStatusException(int cmd,
int id,
int substatus,
String msg,
String lang)
throws IOException
IOExceptionprotected byte[] checkHandle(int cmd,
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,
Buffer buffer)
throws IOException
IOExceptionprotected byte[] handleUnexpectedHandlePacket(int cmd,
int id,
int type,
int length,
Buffer buffer)
throws IOException
IOExceptionprotected SftpClient.Attributes checkAttributes(int cmd, Buffer request) throws IOException
cmd - Command to be sentrequest - Request BufferAttributesIOException - 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 IOException
IOExceptionprotected SftpClient.Attributes handleUnexpectedAttributesPacket(int cmd, int id, int type, int length, Buffer buffer) throws IOException
IOExceptionprotected String checkOneName(int cmd, Buffer request) throws IOException
cmd - Command to be sentrequest - The request BufferIOException - If failed to send/receive or process the responseRawSftpClient.send(int, Buffer),
RawSftpClient.receive(int),
checkOneNameResponse(int, Buffer)protected String checkOneNameResponse(int cmd, Buffer buffer) throws IOException
IOExceptionprotected String handleUnknownOneNamePacket(int cmd, int id, int type, int length, Buffer buffer) throws IOException
IOExceptionprotected SftpClient.Attributes readAttributes(Buffer buffer) throws IOException
IOExceptionprotected void writeAttributes(Buffer buffer, SftpClient.Attributes attributes) throws IOException
IOExceptionpublic SftpClient.CloseableHandle open(String path, Collection<SftpClient.OpenMode> options) throws IOException
SftpClientopen in interface SftpClientpath - The remote pathoptions - The desired mode - if none specified
then SftpClient.OpenMode.Read is assumedSftpClient.CloseableHandleIOException - If failed to open the remote filepublic void close(SftpClient.Handle handle) throws IOException
SftpClientopen methodsclose in interface SftpClienthandle - The Handle to closeIOException - If failed to executepublic void remove(String path) throws IOException
remove in interface SftpClientpath - The remote path to removeIOException - If failed to executepublic void rename(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) throws IOException
rename in interface SftpClientIOExceptionpublic int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) throws 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 reachedIOException - If failed to read the dataprotected int checkData(int cmd,
Buffer request,
int dstOffset,
byte[] dst,
AtomicReference<Boolean> eofSignalled)
throws IOException
IOExceptionprotected int checkDataResponse(int cmd,
Buffer buffer,
int dstoff,
byte[] dst,
AtomicReference<Boolean> eofSignalled)
throws IOException
IOExceptionprotected int handleUnknownDataPacket(int cmd,
int id,
int type,
int length,
Buffer buffer)
throws IOException
IOExceptionpublic void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws 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 writeIOException - If failed to write the datapublic void mkdir(String path) throws IOException
SftpClientmkdir in interface SftpClientpath - Remote directory pathIOException - If failed to executepublic void rmdir(String path) throws IOException
SftpClientrmdir in interface SftpClientpath - Remote directory pathIOException - If failed to executepublic SftpClient.CloseableHandle openDir(String path) throws IOException
SftpClientopenDir in interface SftpClientpath - Remote directory pathSftpClient.HandleIOException - If failed to executepublic List<SftpClient.DirEntry> readDir(SftpClient.Handle handle, AtomicReference<Boolean> eolIndicator) throws 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 entriesIOException - If failed to access the remote siteprotected List<SftpClient.DirEntry> checkDirResponse(int cmd, Buffer buffer, AtomicReference<Boolean> eolIndicator) throws IOException
IOExceptionprotected List<SftpClient.DirEntry> handleUnknownDirListingPacket(int cmd, int id, int type, int length, Buffer buffer) throws IOException
IOExceptionprotected IOException handleUnexpectedPacket(int cmd, int expected, int id, int type, int length, Buffer buffer) throws IOException
IOExceptionpublic String canonicalPath(String path) throws IOException
SftpClientcanonicalPath in interface SftpClientpath - 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
SftpClientstat in interface SftpClientpath - The remote pathSftpClient.AttributesIOException - If failed to executepublic SftpClient.Attributes lstat(String path) throws IOException
SftpClientlstat in interface SftpClientpath - The remote pathSftpClient.AttributesIOException - If failed to executepublic SftpClient.Attributes stat(SftpClient.Handle handle) throws IOException
SftpClientstat in interface SftpClienthandle - The SftpClient.Handle obtained via one of the open callsSftpClient.AttributesIOException - If failed to executepublic void setStat(String path, SftpClient.Attributes attributes) throws IOException
SftpClientsetStat in interface SftpClientpath - The remote pathattributes - The SftpClient.Attributes to updateIOException - If failed to executepublic void setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws IOException
SftpClientsetStat in interface SftpClienthandle - 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
SftpClientreadLink in interface SftpClientpath - Remote path that represents a linkIOException - If failed to executepublic void link(String linkPath, String targetPath, boolean symbolic) throws 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 oneIOException - If failed to executepublic void lock(SftpClient.Handle handle, long offset, long length, int mask) throws IOException
lock in interface SftpClientIOExceptionpublic void unlock(SftpClient.Handle handle, long offset, long length) throws IOException
unlock in interface SftpClientIOExceptionCopyright © 2008–2017 The Apache Software Foundation. All rights reserved.