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 Set<SftpClient.OpenMode> |
DEFAULT_CHANNEL_MODES
Default modes for opening a channel if no specific modes specified
|
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 |
BY_NAME_COMPARATOR, NAME_EXTRACTOR
Modifier and Type | Method and Description |
---|---|
String |
canonicalPath(String path)
The effective "normalized" remote path
|
void |
close(SftpClient.Handle handle)
Close the handle obtained from one of the
open methods |
default <E extends SftpClientExtension> |
getExtension(Class<? extends E> extensionType) |
SftpClientExtension |
getExtension(SftpClientExtensionFactory factory) |
default SftpClientExtension |
getExtension(String extensionName) |
default String |
getName() |
Charset |
getNameDecodingCharset() |
NavigableMap<String,byte[]> |
getServerExtensions() |
int |
getVersion() |
boolean |
isClosing() |
void |
link(String linkPath,
String targetPath,
boolean symbolic)
Create a link
|
Iterable<SftpClient.DirEntry> |
listDir(SftpClient.Handle handle) |
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
|
default 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)
|
default SftpClient.CloseableHandle |
open(String path,
SftpClient.OpenMode... options)
Opens a remote file with the specified mode(s)
|
SftpClient.CloseableHandle |
openDir(String path)
Obtain a handle for a directory
|
FileChannel |
openRemoteFileChannel(String path,
Collection<SftpClient.OpenMode> modes)
Opens an
FileChannel on the specified remote path |
default FileChannel |
openRemoteFileChannel(String path,
SftpClient.OpenMode... modes) |
default FileChannel |
openRemotePathChannel(String path,
Collection<? extends OpenOption> options) |
default FileChannel |
openRemotePathChannel(String path,
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,
AtomicReference<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,
AtomicReference<Boolean> eofSignalled)
Reads data from the open (file) handle
|
default InputStream |
read(String path) |
default InputStream |
read(String path,
Collection<SftpClient.OpenMode> mode) |
default InputStream |
read(String path,
int bufferSize) |
InputStream |
read(String path,
int bufferSize,
Collection<SftpClient.OpenMode> mode)
Read a remote file's data via an input stream
|
default InputStream |
read(String path,
int bufferSize,
SftpClient.OpenMode... mode) |
default InputStream |
read(String path,
SftpClient.OpenMode... mode) |
default List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle) |
List<SftpClient.DirEntry> |
readDir(SftpClient.Handle handle,
AtomicReference<Boolean> eolIndicator) |
Iterable<SftpClient.DirEntry> |
readDir(String path) |
default Collection<SftpClient.DirEntry> |
readEntries(String path)
Reads all entries available for a directory
|
String |
readLink(String path)
Retrieve target of a link
|
void |
remove(String path) |
default void |
rename(String oldPath,
String newPath) |
void |
rename(String oldPath,
String newPath,
Collection<SftpClient.CopyMode> options) |
default void |
rename(String oldPath,
String newPath,
SftpClient.CopyMode... options) |
void |
rmdir(String path)
Remove remote directory
|
void |
setNameDecodingCharset(Charset cs) |
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
|
default SftpClient |
singleSessionInstance()
Creates an
SftpClient instance that also closes the underlying client session
when the client instance is closed. |
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
|
default void |
symLink(String linkPath,
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 OutputStream |
write(String path) |
default OutputStream |
write(String path,
Collection<SftpClient.OpenMode> mode) |
default OutputStream |
write(String path,
int bufferSize) |
OutputStream |
write(String path,
int bufferSize,
Collection<SftpClient.OpenMode> mode)
Write to a remote file via an output stream
|
default OutputStream |
write(String path,
int bufferSize,
SftpClient.OpenMode... mode) |
default OutputStream |
write(String path,
SftpClient.OpenMode... mode) |
getSession
getSessionContext
getClientSession
findByName, findFirstMatchByName, getNameList, getNames, ofName, removeByName, safeCompareByName
getChannel, getClientChannel
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 Set<SftpClient.OpenMode> DEFAULT_CHANNEL_MODES
int getVersion()
default String getName()
getName
in interface NamedResource
Charset getNameDecodingCharset()
null
) Charset
used to decode referenced files/folders namesSftpModuleProperties.NAME_DECODING_CHARSET
void setNameDecodingCharset(Charset cs)
NavigableMap<String,byte[]> getServerExtensions()
NavigableMap
of the reported server extensions. where key=extension name (case
insensitive)boolean isClosing()
default SftpClient.CloseableHandle open(String path) throws IOException
path
- The remote pathSftpClient.CloseableHandle
IOException
- If failed to open the remote fileopen(String, Collection)
default SftpClient.CloseableHandle open(String path, SftpClient.OpenMode... options) throws IOException
path
- The remote pathoptions
- The desired mode - if none specified then SftpClient.OpenMode.Read
is assumedSftpClient.CloseableHandle
IOException
- If failed to open the remote fileopen(String, Collection)
SftpClient.CloseableHandle open(String path, Collection<SftpClient.OpenMode> options) throws IOException
path
- The remote pathoptions
- The desired mode - if none specified then SftpClient.OpenMode.Read
is assumedSftpClient.CloseableHandle
IOException
- If failed to open the remote filevoid close(SftpClient.Handle handle) throws IOException
open
methodshandle
- The Handle
to closeIOException
- If failed to executevoid remove(String path) throws IOException
path
- The remote path to removeIOException
- If failed to executedefault void rename(String oldPath, String newPath) throws IOException
IOException
default void rename(String oldPath, String newPath, SftpClient.CopyMode... options) throws IOException
IOException
void rename(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) throws IOException
IOException
default int read(SftpClient.Handle handle, long fileOffset, byte[] dst) throws IOException
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 dataread(Handle, long, byte[], int, int)
default int read(SftpClient.Handle handle, long fileOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws 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 reachedIOException
- 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 IOException
IOException
int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) throws 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 reachedIOException
- If failed to read the datadefault void write(SftpClient.Handle handle, long fileOffset, byte[] src) throws IOException
IOException
void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws 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 writeIOException
- If failed to write the datavoid mkdir(String path) throws IOException
path
- Remote directory pathIOException
- If failed to executevoid rmdir(String path) throws IOException
path
- Remote directory pathIOException
- If failed to executeSftpClient.CloseableHandle openDir(String path) throws IOException
path
- Remote directory pathSftpClient.Handle
IOException
- If failed to executedefault List<SftpClient.DirEntry> readDir(SftpClient.Handle handle) throws 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)
IOException
- If failed to access the remote siteList<SftpClient.DirEntry> readDir(SftpClient.Handle handle, AtomicReference<Boolean> eolIndicator) throws 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 entriesIOException
- If failed to access the remote siteIterable<SftpClient.DirEntry> listDir(SftpClient.Handle handle) throws 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 onceIOException
- If failed to access the directoryString canonicalPath(String path) throws IOException
path
- The requested path - may be relative, and/or contain dots - e.g., ".",
"..", "./foo", "../bar"IOException
- If failed to executeSftpClient.Attributes stat(String path) throws IOException
path
- The remote pathSftpClient.Attributes
IOException
- If failed to executeSftpClient.Attributes lstat(String path) throws IOException
path
- The remote pathSftpClient.Attributes
IOException
- If failed to executeSftpClient.Attributes stat(SftpClient.Handle handle) throws IOException
handle
- The SftpClient.Handle
obtained via one of the open
callsSftpClient.Attributes
IOException
- If failed to executevoid setStat(String path, SftpClient.Attributes attributes) throws IOException
path
- The remote pathattributes
- The SftpClient.Attributes
to updateIOException
- If failed to executevoid setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws IOException
handle
- The SftpClient.Handle
obtained via one of the open
callsattributes
- The SftpClient.Attributes
to updateIOException
- If failed to executeString readLink(String path) throws IOException
path
- Remote path that represents a linkIOException
- If failed to executedefault void symLink(String linkPath, String targetPath) throws IOException
linkPath
- The link locationtargetPath
- The referenced target by the linkIOException
- If failed to executelink(String, String, boolean)
void link(String linkPath, String targetPath, boolean symbolic) throws IOException
linkPath
- The link locationtargetPath
- The referenced target by the linksymbolic
- If true
then make this a symbolic link, otherwise a hard oneIOException
- If failed to executevoid lock(SftpClient.Handle handle, long offset, long length, int mask) throws IOException
IOException
void unlock(SftpClient.Handle handle, long offset, long length) throws IOException
IOException
default FileChannel openRemotePathChannel(String path, OpenOption... options) throws IOException
IOException
default FileChannel openRemotePathChannel(String path, Collection<? extends OpenOption> options) throws IOException
IOException
default FileChannel openRemoteFileChannel(String path, SftpClient.OpenMode... modes) throws IOException
IOException
FileChannel openRemoteFileChannel(String path, Collection<SftpClient.OpenMode> modes) throws 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.IOException
- If failed to open the channelChannels.newInputStream(java.nio.channels.ReadableByteChannel)
,
Channels.newOutputStream(java.nio.channels.WritableByteChannel)
Iterable<SftpClient.DirEntry> readDir(String path) throws IOException
path
- The remote directory pathIterable
that can be used to iterate over all the directory entries (unlike
readDir(Handle)
)IOException
- If failed to access the remote sitereadDir(Handle)
default Collection<SftpClient.DirEntry> readEntries(String path) throws IOException
path
- Remote directory pathCollection
of all the entries in the remote directoryIOException
- If failed to retrieve the entriesreadDir(String)
default InputStream read(String path) throws IOException
IOException
default InputStream read(String path, int bufferSize) throws IOException
IOException
default InputStream read(String path, SftpClient.OpenMode... mode) throws IOException
IOException
default InputStream read(String path, int bufferSize, SftpClient.OpenMode... mode) throws IOException
IOException
default InputStream read(String path, Collection<SftpClient.OpenMode> mode) throws IOException
IOException
InputStream read(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException
path
- The remote file pathbufferSize
- The internal read buffer sizemode
- The remote file SftpClient.OpenMode
sInputStream
for reading the remote file dataIOException
- If failed to executedefault OutputStream write(String path) throws IOException
IOException
default OutputStream write(String path, int bufferSize) throws IOException
IOException
default OutputStream write(String path, SftpClient.OpenMode... mode) throws IOException
IOException
default OutputStream write(String path, int bufferSize, SftpClient.OpenMode... mode) throws IOException
IOException
default OutputStream write(String path, Collection<SftpClient.OpenMode> mode) throws IOException
IOException
OutputStream write(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException
path
- The remote file pathbufferSize
- The internal write buffer sizemode
- The remote file SftpClient.OpenMode
sOutputStream
for writing the dataIOException
- If failed to executedefault <E extends SftpClientExtension> E getExtension(Class<? extends E> extensionType)
E
- The generic extension typeextensionType
- The extension typeOptionalFeature.isSupported()
- null
if this extension type is not
implemented by the clientgetServerExtensions()
default SftpClientExtension getExtension(String extensionName)
extensionName
- The extension nameOptionalFeature.isSupported()
- null
if this extension type is not
implemented by the clientgetServerExtensions()
SftpClientExtension getExtension(SftpClientExtensionFactory factory)
factory
- The SftpClientExtensionFactory
instance to use - ignored if null
OptionalFeature.isSupported()
- null
if this extension type is not
implemented by the clientdefault SftpClient singleSessionInstance()
SftpClient
instance that also closes the underlying client session
when the client instance is closed.Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.