public interface SftpClient extends SubsystemClient
Modifier and Type | Interface and Description |
---|---|
static class |
SftpClient.Attribute |
static class |
SftpClient.Attributes |
static class |
SftpClient.CloseableHandle |
static class |
SftpClient.CopyMode |
static class |
SftpClient.DirEntry |
static class |
SftpClient.Handle |
static class |
SftpClient.OpenMode |
Modifier and Type | Field and Description |
---|---|
static java.util.Set<SftpClient.OpenMode> |
DEFAULT_CHANNEL_MODES
Default modes for opening a channel if no specific modes specified
|
static long |
DEFAULT_CHANNEL_OPEN_TIMEOUT |
static java.nio.charset.Charset |
DEFAULT_NAME_DECODING_CHARSET
Default value of "sftp-name-decoding-charset"
|
static long |
DEFAULT_WAIT_TIMEOUT |
static SftpClient.DirEntry[] |
EMPTY_DIR_ENTRIES |
static int |
IO_BUFFER_SIZE |
static int |
MIN_BUFFER_SIZE |
static int |
MIN_READ_BUFFER_SIZE |
static int |
MIN_WRITE_BUFFER_SIZE |
static java.lang.String |
NAME_DECODING_CHARSET
Used to indicate the
Charset (or its name) for decoding referenced files/folders names - extracted from
the client session when 1st initialized. |
static java.lang.String |
SFTP_CHANNEL_OPEN_TIMEOUT
Property that can be used on the
FactoryManager to control the internal timeout
used by the client to open a channel. |
BY_NAME_COMPARATOR, NAME_EXTRACTOR
Modifier and Type | Method and Description |
---|---|
java.lang.String |
canonicalPath(java.lang.String path)
The effective "normalized" remote path
|
void |
close(SftpClient.Handle handle)
Close the handle obtained from one of the
open methods |
<E extends SftpClientExtension> |
getExtension(java.lang.Class<? extends E> extensionType) |
SftpClientExtension |
getExtension(java.lang.String extensionName) |
default java.lang.String |
getName() |
java.nio.charset.Charset |
getNameDecodingCharset() |
java.util.NavigableMap<java.lang.String,byte[]> |
getServerExtensions() |
int |
getVersion() |
boolean |
isClosing() |
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
|
default SftpClient.CloseableHandle |
open(java.lang.String path)
Opens a remote file for read
|
SftpClient.CloseableHandle |
open(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> options)
Opens a remote file with the specified mode(s)
|
default SftpClient.CloseableHandle |
open(java.lang.String path,
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 |
default java.nio.channels.FileChannel |
openRemoteFileChannel(java.lang.String path,
SftpClient.OpenMode... modes) |
default java.nio.channels.FileChannel |
openRemotePathChannel(java.lang.String path,
java.util.Collection<? extends java.nio.file.OpenOption> options) |
default java.nio.channels.FileChannel |
openRemotePathChannel(java.lang.String path,
java.nio.file.OpenOption... options) |
default int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst)
Reads data from the open (file) handle
|
default int |
read(SftpClient.Handle handle,
long fileOffset,
byte[] dst,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled)
Reads data from the open (file) handle
|
default 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,
java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled)
Reads data from the open (file) handle
|
default java.io.InputStream |
read(java.lang.String path) |
default java.io.InputStream |
read(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> mode) |
default java.io.InputStream |
read(java.lang.String path,
int bufferSize) |
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
|
default java.io.InputStream |
read(java.lang.String path,
int bufferSize,
SftpClient.OpenMode... mode) |
default java.io.InputStream |
read(java.lang.String path,
SftpClient.OpenMode... mode) |
default java.util.List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle) |
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) |
default void |
rename(java.lang.String oldPath,
java.lang.String newPath) |
void |
rename(java.lang.String oldPath,
java.lang.String newPath,
java.util.Collection<SftpClient.CopyMode> options) |
default void |
rename(java.lang.String oldPath,
java.lang.String newPath,
SftpClient.CopyMode... options) |
void |
rmdir(java.lang.String path)
Remove remote directory
|
void |
setNameDecodingCharset(java.nio.charset.Charset cs) |
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
|
default void |
symLink(java.lang.String linkPath,
java.lang.String targetPath)
Create symbolic link
|
void |
unlock(SftpClient.Handle handle,
long offset,
long length) |
default void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src) |
void |
write(SftpClient.Handle handle,
long fileOffset,
byte[] src,
int srcOffset,
int len)
Write data to (open) file handle
|
default java.io.OutputStream |
write(java.lang.String path) |
default java.io.OutputStream |
write(java.lang.String path,
java.util.Collection<SftpClient.OpenMode> mode) |
default java.io.OutputStream |
write(java.lang.String path,
int bufferSize) |
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
|
default java.io.OutputStream |
write(java.lang.String path,
int bufferSize,
SftpClient.OpenMode... mode) |
default java.io.OutputStream |
write(java.lang.String path,
SftpClient.OpenMode... mode) |
getSession
getSessionContext
getClientSession
findByName, getNameList, getNames, ofName, removeByName
getChannel, getClientChannel
static final java.lang.String NAME_DECODING_CHARSET
Charset
(or its name) for decoding referenced files/folders names - extracted from
the client session when 1st initialized.static final java.nio.charset.Charset DEFAULT_NAME_DECODING_CHARSET
static final SftpClient.DirEntry[] EMPTY_DIR_ENTRIES
static final int MIN_BUFFER_SIZE
static final int MIN_READ_BUFFER_SIZE
static final int MIN_WRITE_BUFFER_SIZE
static final int IO_BUFFER_SIZE
static final long DEFAULT_WAIT_TIMEOUT
static final java.lang.String SFTP_CHANNEL_OPEN_TIMEOUT
FactoryManager
to control the internal timeout
used by the client to open a channel. If not specified then DEFAULT_CHANNEL_OPEN_TIMEOUT
value is usedstatic final long DEFAULT_CHANNEL_OPEN_TIMEOUT
static final java.util.Set<SftpClient.OpenMode> DEFAULT_CHANNEL_MODES
int getVersion()
default java.lang.String getName()
getName
in interface NamedResource
java.nio.charset.Charset getNameDecodingCharset()
null
) Charset
used to decode referenced files/folders namesNAME_DECODING_CHARSET
void setNameDecodingCharset(java.nio.charset.Charset cs)
java.util.NavigableMap<java.lang.String,byte[]> getServerExtensions()
NavigableMap
of the reported server extensions. where key=extension name (case
insensitive)boolean isClosing()
default SftpClient.CloseableHandle open(java.lang.String path) throws java.io.IOException
path
- The remote pathSftpClient.CloseableHandle
java.io.IOException
- If failed to open the remote fileopen(String, Collection)
default SftpClient.CloseableHandle open(java.lang.String path, SftpClient.OpenMode... options) throws java.io.IOException
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 fileopen(String, Collection)
SftpClient.CloseableHandle open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options) throws java.io.IOException
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 filevoid close(SftpClient.Handle handle) throws java.io.IOException
open
methodshandle
- The Handle
to closejava.io.IOException
- If failed to executevoid remove(java.lang.String path) throws java.io.IOException
path
- The remote path to removejava.io.IOException
- If failed to executedefault void rename(java.lang.String oldPath, java.lang.String newPath) throws java.io.IOException
java.io.IOException
default void rename(java.lang.String oldPath, java.lang.String newPath, SftpClient.CopyMode... options) throws java.io.IOException
java.io.IOException
void rename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options) throws java.io.IOException
java.io.IOException
default int read(SftpClient.Handle handle, long fileOffset, byte[] dst) throws java.io.IOException
handle
- The file SftpClient.Handle
to read fromfileOffset
- The file offset to read fromdst
- The destination buffer-1
if EOF reachedjava.io.IOException
- If failed to read the dataread(Handle, long, byte[], int, int)
default int read(SftpClient.Handle handle, long fileOffset, byte[] dst, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eofSignalled) throws java.io.IOException
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 reachedjava.io.IOException
- If failed to read the dataread(Handle, long, byte[], int, int, AtomicReference)
,
SFTP v6 -
section 9.3default int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws java.io.IOException
java.io.IOException
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
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 datadefault void write(SftpClient.Handle handle, long fileOffset, byte[] src) throws java.io.IOException
java.io.IOException
void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws java.io.IOException
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 datavoid mkdir(java.lang.String path) throws java.io.IOException
path
- Remote directory pathjava.io.IOException
- If failed to executevoid rmdir(java.lang.String path) throws java.io.IOException
path
- Remote directory pathjava.io.IOException
- If failed to executeSftpClient.CloseableHandle openDir(java.lang.String path) throws java.io.IOException
path
- Remote directory pathSftpClient.Handle
java.io.IOException
- If failed to executedefault java.util.List<SftpClient.DirEntry> readDir(SftpClient.Handle handle) throws java.io.IOException
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 readDir(String)
java.io.IOException
- If failed to access the remote sitejava.util.List<SftpClient.DirEntry> readDir(SftpClient.Handle handle, java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> eolIndicator) throws java.io.IOException
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 sitejava.lang.Iterable<SftpClient.DirEntry> listDir(SftpClient.Handle handle) throws java.io.IOException
handle
- A directory SftpClient.Handle
Iterable
that can be used to iterate over all the directory entries (like
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 directoryjava.lang.String canonicalPath(java.lang.String path) throws java.io.IOException
path
- The requested path - may be relative, and/or contain dots - e.g., ".",
"..", "./foo", "../bar"java.io.IOException
- If failed to executeSftpClient.Attributes stat(java.lang.String path) throws java.io.IOException
path
- The remote pathSftpClient.Attributes
java.io.IOException
- If failed to executeSftpClient.Attributes lstat(java.lang.String path) throws java.io.IOException
path
- The remote pathSftpClient.Attributes
java.io.IOException
- If failed to executeSftpClient.Attributes stat(SftpClient.Handle handle) throws java.io.IOException
handle
- The SftpClient.Handle
obtained via one of the open
callsSftpClient.Attributes
java.io.IOException
- If failed to executevoid setStat(java.lang.String path, SftpClient.Attributes attributes) throws java.io.IOException
path
- The remote pathattributes
- The SftpClient.Attributes
to updatejava.io.IOException
- If failed to executevoid setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws java.io.IOException
handle
- The SftpClient.Handle
obtained via one of the open
callsattributes
- The SftpClient.Attributes
to updatejava.io.IOException
- If failed to executejava.lang.String readLink(java.lang.String path) throws java.io.IOException
path
- Remote path that represents a linkjava.io.IOException
- If failed to executedefault void symLink(java.lang.String linkPath, java.lang.String targetPath) throws java.io.IOException
linkPath
- The link locationtargetPath
- The referenced target by the linkjava.io.IOException
- If failed to executelink(String, String, boolean)
void link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic) throws java.io.IOException
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 executevoid lock(SftpClient.Handle handle, long offset, long length, int mask) throws java.io.IOException
java.io.IOException
void unlock(SftpClient.Handle handle, long offset, long length) throws java.io.IOException
java.io.IOException
default java.nio.channels.FileChannel openRemotePathChannel(java.lang.String path, java.nio.file.OpenOption... options) throws java.io.IOException
java.io.IOException
default java.nio.channels.FileChannel openRemotePathChannel(java.lang.String path, java.util.Collection<? extends java.nio.file.OpenOption> options) throws java.io.IOException
java.io.IOException
default java.nio.channels.FileChannel openRemoteFileChannel(java.lang.String path, SftpClient.OpenMode... modes) throws java.io.IOException
java.io.IOException
java.nio.channels.FileChannel openRemoteFileChannel(java.lang.String path, java.util.Collection<SftpClient.OpenMode> modes) throws java.io.IOException
FileChannel
on the specified remote pathpath
- The remote pathmodes
- The access mode(s) - if null
/empty then the 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)
java.lang.Iterable<SftpClient.DirEntry> readDir(java.lang.String path) throws java.io.IOException
path
- The remote directory pathIterable
that can be used to iterate over all the directory entries (unlike
readDir(Handle)
)java.io.IOException
- If failed to access the remote sitereadDir(Handle)
default java.io.InputStream read(java.lang.String path) throws java.io.IOException
java.io.IOException
default java.io.InputStream read(java.lang.String path, int bufferSize) throws java.io.IOException
java.io.IOException
default java.io.InputStream read(java.lang.String path, SftpClient.OpenMode... mode) throws java.io.IOException
java.io.IOException
default java.io.InputStream read(java.lang.String path, int bufferSize, SftpClient.OpenMode... mode) throws java.io.IOException
java.io.IOException
default java.io.InputStream read(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
java.io.IOException
java.io.InputStream read(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
path
- The remote file pathbufferSize
- The internal read buffer sizemode
- The remote file SftpClient.OpenMode
sInputStream
for reading the remote file datajava.io.IOException
- If failed to executedefault java.io.OutputStream write(java.lang.String path) throws java.io.IOException
java.io.IOException
default java.io.OutputStream write(java.lang.String path, int bufferSize) throws java.io.IOException
java.io.IOException
default java.io.OutputStream write(java.lang.String path, SftpClient.OpenMode... mode) throws java.io.IOException
java.io.IOException
default java.io.OutputStream write(java.lang.String path, int bufferSize, SftpClient.OpenMode... mode) throws java.io.IOException
java.io.IOException
default java.io.OutputStream write(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
java.io.IOException
java.io.OutputStream write(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
path
- The remote file pathbufferSize
- The internal write buffer sizemode
- The remote file SftpClient.OpenMode
sOutputStream
for writing the datajava.io.IOException
- If failed to execute<E extends SftpClientExtension> E getExtension(java.lang.Class<? extends E> extensionType)
E
- The generic extension typeextensionType
- The extension typeOptionalFeature.isSupported()
- null
if this extension type is not
implemented by the clientgetServerExtensions()
SftpClientExtension getExtension(java.lang.String extensionName)
extensionName
- The extension nameOptionalFeature.isSupported()
- null
if this extension type is not
implemented by the clientgetServerExtensions()