public abstract class AbstractSftpClient extends AbstractSubsystemClient implements SftpClient, RawSftpClient
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenMode
NamedResource.Utils
log
DEFAULT_CHANNEL_OPEN_TIMEOUT, DEFAULT_READ_BUFFER_SIZE, DEFAULT_WAIT_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE, 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) |
protected SftpClient.Attributes |
checkAttributes(Buffer buffer) |
protected SftpClient.Attributes |
checkAttributes(int cmd,
Buffer request) |
protected int |
checkData(Buffer buffer,
int dstoff,
byte[] dst,
AtomicReference<Boolean> eofSignalled) |
protected int |
checkData(int cmd,
Buffer request,
int dstOffset,
byte[] dst,
AtomicReference<Boolean> eofSignalled) |
protected List<SftpClient.DirEntry> |
checkDir(Buffer buffer,
AtomicReference<Boolean> eolIndicator) |
protected byte[] |
checkHandle(Buffer buffer) |
protected byte[] |
checkHandle(int cmd,
Buffer request) |
protected String |
checkOneName(Buffer buffer) |
protected String |
checkOneName(int cmd,
Buffer request) |
protected void |
checkStatus(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 |
checkStatus(int cmd,
Buffer request)
Sends the specified command, waits for the response and then invokes
checkStatus(Buffer) |
protected void |
checkStatus(int id,
int substatus,
String msg,
String lang) |
void |
close(SftpClient.Handle handle) |
<E extends SftpClientExtension> |
getExtension(Class<? extends E> extensionType) |
protected SftpClientExtension |
getExtension(SftpClientExtensionFactory factory) |
SftpClientExtension |
getExtension(String extensionName) |
String |
getName() |
protected Map<String,Object> |
getParsedServerExtensions() |
protected Map<String,Object> |
getParsedServerExtensions(Map<String,byte[]> extensions) |
protected SftpClient.Attributes |
handleUnexpectedAttributesPacket(int id,
int type,
int length,
Buffer buffer) |
protected byte[] |
handleUnexpectedHandlePacket(int id,
int type,
int length,
Buffer buffer) |
protected IOException |
handleUnexpectedPacket(int expected,
int id,
int type,
int length,
Buffer buffer) |
protected int |
handleUnknownDataPacket(int id,
int type,
int length,
Buffer buffer) |
protected List<SftpClient.DirEntry> |
handleUnknownDirListingPacket(int id,
int type,
int length,
Buffer buffer) |
protected String |
handleUnknownOneNamePacket(int id,
int type,
int length,
Buffer buffer) |
void |
link(String linkPath,
String targetPath,
boolean symbolic) |
void |
lock(SftpClient.Handle handle,
long offset,
long length,
int mask) |
SftpClient.Attributes |
lstat(String path) |
void |
mkdir(String path) |
SftpClient.CloseableHandle |
open(String path)
Opens a remote file for read
|
SftpClient.CloseableHandle |
open(String path,
Collection<SftpClient.OpenMode> options)
Opens a remote file with the specified mode(s)
|
SftpClient.CloseableHandle |
open(String path,
SftpClient.OpenMode... options)
Opens a remote file with the specified mode(s)
|
SftpClient.CloseableHandle |
openDir(String path) |
int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst)
Reads data from the open (file) handle
|
int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst,
AtomicReference<Boolean> eofSignalled)
Reads data from the open (file) handle
|
int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst,
int dstOffset,
int len) |
int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst,
int dstOffset,
int len,
AtomicReference<Boolean> eofSignalled)
Reads data from the open (file) handle
|
InputStream |
read(String path) |
InputStream |
read(String path,
Collection<SftpClient.OpenMode> mode) |
InputStream |
read(String path,
int bufferSize) |
InputStream |
read(String path,
int bufferSize,
Collection<SftpClient.OpenMode> mode) |
InputStream |
read(String path,
int bufferSize,
SftpClient.OpenMode... mode) |
InputStream |
read(String path,
SftpClient.OpenMode... mode) |
protected SftpClient.Attributes |
readAttributes(Buffer buffer) |
List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle) |
List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle,
AtomicReference<Boolean> eolIndicator) |
Iterable<SftpClient.DirEntry> |
readDir(String path) |
String |
readLink(String path) |
void |
remove(String path) |
void |
rename(String oldPath,
String newPath) |
void |
rename(String oldPath,
String newPath,
Collection<SftpClient.CopyMode> options) |
void |
rename(String oldPath,
String newPath,
SftpClient.CopyMode... options) |
void |
rmdir(String path) |
void |
setStat(SftpClient.Handle handle,
SftpClient.Attributes attributes) |
void |
setStat(String path,
SftpClient.Attributes attributes) |
SftpClient.Attributes |
stat(SftpClient.Handle handle) |
SftpClient.Attributes |
stat(String path) |
void |
symLink(String linkPath,
String targetPath) |
protected void |
throwStatusException(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) |
void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src,
int srcOffset,
int len) |
OutputStream |
write(String path) |
OutputStream |
write(String path,
Collection<SftpClient.OpenMode> mode) |
OutputStream |
write(String path,
int bufferSize) |
OutputStream |
write(String path,
int bufferSize,
Collection<SftpClient.OpenMode> mode) |
OutputStream |
write(String path,
int bufferSize,
SftpClient.OpenMode... mode) |
OutputStream |
write(String path,
SftpClient.OpenMode... mode) |
protected void |
writeAttributes(Buffer buffer,
SftpClient.Attributes attributes) |
getSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getServerExtensions, getVersion, isClosing
getClientChannel
getSession
getClientSession
receive, send
public String getName()
getName
in interface NamedResource
public SftpClient.CloseableHandle open(String path) throws IOException
SftpClient
open
in interface SftpClient
path
- The remote pathSftpClient.CloseableHandle
IOException
- If failed to open the remote filepublic SftpClient.CloseableHandle open(String path, 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 rename(String oldPath, String newPath) throws IOException
rename
in interface SftpClient
IOException
public void rename(String oldPath, String newPath, SftpClient.CopyMode... options) throws IOException
rename
in interface SftpClient
IOException
public InputStream read(String path) throws IOException
read
in interface SftpClient
IOException
public InputStream read(String path, int bufferSize) throws IOException
read
in interface SftpClient
IOException
public InputStream read(String path, SftpClient.OpenMode... mode) throws IOException
read
in interface SftpClient
IOException
public InputStream read(String path, int bufferSize, SftpClient.OpenMode... mode) throws IOException
read
in interface SftpClient
IOException
public InputStream read(String path, Collection<SftpClient.OpenMode> mode) throws IOException
read
in interface SftpClient
IOException
public OutputStream write(String path) throws IOException
write
in interface SftpClient
IOException
public OutputStream write(String path, int bufferSize) throws IOException
write
in interface SftpClient
IOException
public OutputStream write(String path, SftpClient.OpenMode... mode) throws IOException
write
in interface SftpClient
IOException
public OutputStream write(String path, Collection<SftpClient.OpenMode> mode) throws IOException
write
in interface SftpClient
IOException
public OutputStream write(String path, int bufferSize, SftpClient.OpenMode... mode) throws IOException
write
in interface SftpClient
IOException
public void write(SftpClient.Handle handle, long fileOffset, byte[] src) throws IOException
write
in interface SftpClient
IOException
public void symLink(String linkPath, String targetPath) throws IOException
symLink
in interface SftpClient
IOException
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 void checkStatus(int cmd, Buffer request) throws IOException
checkStatus(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)
,
checkStatus(Buffer)
protected void checkStatus(Buffer buffer) throws IOException
SSH_FXP_STATUS
one,
and if so whether the substatus is SSH_FX_OK
.buffer
- The received response Buffer
IOException
- If response does not carry a status or carries
a bad status codecheckStatus(int, int, String, String)
protected void checkStatus(int id, int substatus, String msg, String lang) throws IOException
id
- The request idsubstatus
- The sub-status valuemsg
- The messagelang
- The languageIOException
- if the sub-status is not SSH_FX_OK
throwStatusException(int, int, String, String)
protected void throwStatusException(int id, int substatus, String msg, String lang) throws IOException
IOException
protected 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)
,
checkHandle(Buffer)
protected byte[] checkHandle(Buffer buffer) throws IOException
IOException
protected byte[] handleUnexpectedHandlePacket(int id, int type, int length, Buffer buffer) throws IOException
IOException
protected SftpClient.Attributes checkAttributes(int cmd, 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)
,
checkAttributes(Buffer)
protected SftpClient.Attributes checkAttributes(Buffer buffer) throws IOException
IOException
protected SftpClient.Attributes handleUnexpectedAttributesPacket(int id, int type, int length, Buffer buffer) throws IOException
IOException
protected String checkOneName(int cmd, 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)
,
checkOneName(Buffer)
protected String checkOneName(Buffer buffer) throws IOException
IOException
protected String handleUnknownOneNamePacket(int id, int type, int length, Buffer buffer) throws IOException
IOException
protected SftpClient.Attributes readAttributes(Buffer buffer) throws IOException
IOException
protected void writeAttributes(Buffer 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
close
in interface SftpClient
IOException
public void remove(String path) throws IOException
remove
in interface SftpClient
IOException
public 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) throws IOException
SftpClient
read
in interface SftpClient
handle
- The file SftpClient.Handle
to read fromfileOffset
- The file offset to read fromdst
- The destination buffer-1
if EOF reachedIOException
- If failed to read the dataSftpClient.read(Handle, long, byte[], int, int)
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, 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 buffereofSignalled
- 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 dataSftpClient.read(Handle, long, byte[], int, int, AtomicReference)
,
SFTP v6 - section 9.3public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws IOException
read
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, Buffer request, int dstOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException
IOException
protected int checkData(Buffer buffer, int dstoff, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException
IOException
protected int handleUnknownDataPacket(int id, int type, int length, Buffer buffer) throws IOException
IOException
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws IOException
write
in interface SftpClient
IOException
public void mkdir(String path) throws IOException
mkdir
in interface SftpClient
IOException
public void rmdir(String path) throws IOException
rmdir
in interface SftpClient
IOException
public SftpClient.CloseableHandle openDir(String path) throws IOException
openDir
in interface SftpClient
IOException
public List<SftpClient.DirEntry> readDir(SftpClient.Handle handle) throws IOException
readDir
in interface SftpClient
handle
- Directory SftpClient.Handle
to read fromList
of entries - null
to indicate no more entries
Note: the list may be incomplete since the client and
server have some internal imposed limit on the number of entries they
can process. Therefore several calls to this method may be required
(until null
). In order to iterate over all the entries use
SftpClient.readDir(String)
IOException
- If failed to access the remote sitepublic 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> checkDir(Buffer buffer, AtomicReference<Boolean> eolIndicator) throws IOException
IOException
protected List<SftpClient.DirEntry> handleUnknownDirListingPacket(int id, int type, int length, Buffer buffer) throws IOException
IOException
protected IOException handleUnexpectedPacket(int expected, int id, int type, int length, Buffer buffer) throws IOException
IOException
public String canonicalPath(String path) throws IOException
canonicalPath
in interface SftpClient
IOException
public SftpClient.Attributes stat(String path) throws IOException
stat
in interface SftpClient
IOException
public SftpClient.Attributes lstat(String path) throws IOException
lstat
in interface SftpClient
IOException
public SftpClient.Attributes stat(SftpClient.Handle handle) throws IOException
stat
in interface SftpClient
IOException
public void setStat(String path, SftpClient.Attributes attributes) throws IOException
setStat
in interface SftpClient
IOException
public void setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws IOException
setStat
in interface SftpClient
IOException
public String readLink(String path) throws IOException
readLink
in interface SftpClient
IOException
public void link(String linkPath, String targetPath, boolean symbolic) throws IOException
link
in interface SftpClient
IOException
public 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
public Iterable<SftpClient.DirEntry> readDir(String path) throws IOException
readDir
in interface SftpClient
path
- The remote directory pathIterable
that can be used to iterate over all the
directory entries (unlike SftpClient.readDir(Handle)
)IOException
- If failed to access the remote siteSftpClient.readDir(Handle)
public InputStream read(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException
read
in interface SftpClient
IOException
public OutputStream write(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException
write
in interface SftpClient
IOException
Copyright © 2008–2016 The Apache Software Foundation. All rights reserved.