Package org.apache.sshd.sftp.client
Interface SftpClient
- All Superinterfaces:
AutoCloseable,Channel,ChannelHolder,ClientChannelHolder,ClientSessionHolder,Closeable,NamedResource,SessionContextHolder,SessionHolder<ClientSession>,SubsystemClient
- All Known Subinterfaces:
FullAccessSftpClient
- All Known Implementing Classes:
AbstractSftpClient,DefaultSftpClient,SftpFileSystem.Wrapper
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumstatic classstatic classstatic enumstatic classstatic classstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Set<SftpClient.OpenMode> Default modes for opening a channel if no specific modes specifiedstatic final SftpClient.DirEntry[]static final intstatic final intstatic final intstatic final intFields inherited from interface org.apache.sshd.common.NamedResource
BY_NAME_COMPARATOR, NAME_EXTRACTOR -
Method Summary
Modifier and TypeMethodDescriptioncanonicalPath(String path) The effective "normalized" remote pathvoidclose(SftpClient.Handle handle) Close the handle obtained from one of theopenmethodsdefault <E extends SftpClientExtension>
EgetExtension(Class<? extends E> extensionType) default SftpClientExtensiongetExtension(String extensionName) getExtension(SftpClientExtensionFactory factory) default StringgetName()NavigableMap<String, byte[]> intbooleanvoidCreate a linklistDir(SftpClient.Handle handle) voidlock(SftpClient.Handle handle, long offset, long length, int mask) Retrieve remote path meta-data - do not follow symbolic linksvoidCreate remote directorydefault SftpClient.CloseableHandleOpens a remote file for readopen(String path, Collection<SftpClient.OpenMode> options) Opens a remote file with the specified mode(s)default SftpClient.CloseableHandleopen(String path, SftpClient.OpenMode... options) Opens a remote file with the specified mode(s)Obtain a handle for a directoryopenRemoteFileChannel(String path, Collection<SftpClient.OpenMode> modes) Opens anFileChannelon the specified remote pathdefault FileChannelopenRemoteFileChannel(String path, SftpClient.OpenMode... modes) default FileChannelopenRemotePathChannel(String path, OpenOption... options) default FileChannelopenRemotePathChannel(String path, Collection<? extends OpenOption> options) default InputStreamdefault InputStreamread(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) Read a remote file's data via an input streamdefault InputStreamread(String path, int bufferSize, SftpClient.OpenMode... mode) default InputStreamread(String path, Collection<SftpClient.OpenMode> mode) default InputStreamread(String path, SftpClient.OpenMode... mode) default intread(SftpClient.Handle handle, long fileOffset, byte[] dst) Reads data from the open (file) handledefault intread(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) intread(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) Reads data from the open (file) handledefault intread(SftpClient.Handle handle, long fileOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) Reads data from the open (file) handledefault List<SftpClient.DirEntry> readDir(SftpClient.Handle handle) readDir(SftpClient.Handle handle, AtomicReference<Boolean> eolIndicator) default Collection<SftpClient.DirEntry> readEntries(String path) Reads all entries available for a directoryRetrieve target of a linkvoiddefault voidvoidrename(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) default voidrename(String oldPath, String newPath, SftpClient.CopyMode... options) voidRemove remote directoryvoidvoidsetStat(String path, SftpClient.Attributes attributes) Update remote node meta-datavoidsetStat(SftpClient.Handle handle, SftpClient.Attributes attributes) Update remote node meta-datadefault SftpClientCreates anSftpClientinstance that also closes the underlyingclient sessionwhen the client instance is closed.Retrieve remote path meta-data - follow symbolic links if encounteredstat(SftpClient.Handle handle) Retrieve file/directory handle meta-datadefault voidCreate symbolic linkvoidunlock(SftpClient.Handle handle, long offset, long length) default OutputStreamdefault OutputStreamwrite(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) Write to a remote file via an output streamdefault OutputStreamwrite(String path, int bufferSize, SftpClient.OpenMode... mode) default OutputStreamwrite(String path, Collection<SftpClient.OpenMode> mode) default OutputStreamwrite(String path, SftpClient.OpenMode... mode) default voidwrite(SftpClient.Handle handle, long fileOffset, byte[] src) voidwrite(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) Write data to (open) file handleMethods inherited from interface org.apache.sshd.client.channel.ClientChannelHolder
getChannel, getClientChannelMethods inherited from interface org.apache.sshd.client.session.ClientSessionHolder
getClientSessionMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContextMethods inherited from interface org.apache.sshd.client.subsystem.SubsystemClient
getSession
-
Field Details
-
EMPTY_DIR_ENTRIES
-
MIN_BUFFER_SIZE
static final int MIN_BUFFER_SIZE- See Also:
-
MIN_READ_BUFFER_SIZE
static final int MIN_READ_BUFFER_SIZE- See Also:
-
MIN_WRITE_BUFFER_SIZE
static final int MIN_WRITE_BUFFER_SIZE- See Also:
-
IO_BUFFER_SIZE
static final int IO_BUFFER_SIZE- See Also:
-
DEFAULT_CHANNEL_MODES
Default modes for opening a channel if no specific modes specified
-
-
Method Details
-
getVersion
int getVersion()- Returns:
- The negotiated SFTP protocol version
-
getName
- Specified by:
getNamein interfaceNamedResource- Returns:
- The resource name
-
getNameDecodingCharset
Charset getNameDecodingCharset()- Returns:
- The (never
null)Charsetused to decode referenced files/folders names - See Also:
-
setNameDecodingCharset
-
getServerExtensions
NavigableMap<String,byte[]> getServerExtensions()- Returns:
- An (unmodifiable)
NavigableMapof the reported server extensions. where key=extension name (case insensitive)
-
isClosing
boolean isClosing() -
open
Opens a remote file for read- Parameters:
path- The remote path- Returns:
- The file's
SftpClient.CloseableHandle - Throws:
IOException- If failed to open the remote file- See Also:
-
open
default SftpClient.CloseableHandle open(String path, SftpClient.OpenMode... options) throws IOException Opens a remote file with the specified mode(s)- Parameters:
path- The remote pathoptions- The desired mode - if none specified thenSftpClient.OpenMode.Readis assumed- Returns:
- The file's
SftpClient.CloseableHandle - Throws:
IOException- If failed to open the remote file- See Also:
-
open
SftpClient.CloseableHandle open(String path, Collection<SftpClient.OpenMode> options) throws IOException Opens a remote file with the specified mode(s)- Parameters:
path- The remote pathoptions- The desired mode - if none specified thenSftpClient.OpenMode.Readis assumed- Returns:
- The file's
SftpClient.CloseableHandle - Throws:
IOException- If failed to open the remote file
-
close
Close the handle obtained from one of theopenmethods- Parameters:
handle- TheHandleto close- Throws:
IOException- If failed to execute
-
remove
- Parameters:
path- The remote path to remove- Throws:
IOException- If failed to execute
-
rename
- Throws:
IOException
-
rename
default void rename(String oldPath, String newPath, SftpClient.CopyMode... options) throws IOException - Throws:
IOException
-
rename
void rename(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) throws IOException - Throws:
IOException
-
read
Reads data from the open (file) handle- Parameters:
handle- The fileSftpClient.Handleto read fromfileOffset- The file offset to read fromdst- The destination buffer- Returns:
- Number of read bytes -
-1if EOF reached - Throws:
IOException- If failed to read the data- See Also:
-
read
default int read(SftpClient.Handle handle, long fileOffset, byte[] dst, AtomicReference<Boolean> eofSignalled) throws IOException Reads data from the open (file) handle- Parameters:
handle- The fileSftpClient.Handleto read fromfileOffset- The file offset to read fromdst- The destination buffereofSignalled- If notnullthen upon return holds a value indicating whether EOF was reached due to the read. Ifnullindicator value then this indication is not available- Returns:
- Number of read bytes -
-1if EOF reached - Throws:
IOException- If failed to read the data- See Also:
-
read
default int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws IOException - Throws:
IOException
-
read
int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len, AtomicReference<Boolean> eofSignalled) throws IOException Reads data from the open (file) handle- Parameters:
handle- The fileSftpClient.Handleto 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 notnullthen upon return holds a value indicating whether EOF was reached due to the read. Ifnullindicator value then this indication is not available- Returns:
- Number of read bytes -
-1if EOF reached - Throws:
IOException- If failed to read the data- See Also:
-
write
- Throws:
IOException
-
write
void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws IOException Write data to (open) file handle- Parameters:
handle- The fileSftpClient.HandlefileOffset- Zero-based offset to write in filesrc- Data buffersrcOffset- Offset of valid data in bufferlen- Number of bytes to write- Throws:
IOException- If failed to write the data
-
mkdir
Create remote directory- Parameters:
path- Remote directory path- Throws:
IOException- If failed to execute
-
rmdir
Remove remote directory- Parameters:
path- Remote directory path- Throws:
IOException- If failed to execute
-
openDir
Obtain a handle for a directory- Parameters:
path- Remote directory path- Returns:
- The associated directory
SftpClient.Handle - Throws:
IOException- If failed to execute
-
readDir
- Parameters:
handle- DirectorySftpClient.Handleto read from- Returns:
- A
Listof entries -nullto 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 (untilnull). In order to iterate over all the entries usereadDir(String) - Throws:
IOException- If failed to access the remote site
-
readDir
List<SftpClient.DirEntry> readDir(SftpClient.Handle handle, AtomicReference<Boolean> eolIndicator) throws IOException - Parameters:
handle- DirectorySftpClient.Handleto read fromeolIndicator- An indicator that can be used to get information whether end of list has been reached - ignored ifnull. Upon return, set value indicates whether all entries have been exhausted - anullvalue means that this information cannot be provided and another call toreadDiris necessary in order to verify that no more entries are pending- Returns:
- A
Listof entries -nullto indicate no more entries - Throws:
IOException- If failed to access the remote site- See Also:
-
listDir
- Parameters:
handle- A directorySftpClient.Handle- Returns:
- An
Iterablethat can be used to iterate over all the directory entries (likereadDir(String)). Note: the iterable instance is not re-usable - i.e., files can be iterated only once - Throws:
IOException- If failed to access the directory
-
canonicalPath
The effective "normalized" remote path- Parameters:
path- The requested path - may be relative, and/or contain dots - e.g., ".", "..", "./foo", "../bar"- Returns:
- The effective "normalized" remote path
- Throws:
IOException- If failed to execute
-
stat
Retrieve remote path meta-data - follow symbolic links if encountered- Parameters:
path- The remote path- Returns:
- The associated
SftpClient.Attributes - Throws:
IOException- If failed to execute
-
lstat
Retrieve remote path meta-data - do not follow symbolic links- Parameters:
path- The remote path- Returns:
- The associated
SftpClient.Attributes - Throws:
IOException- If failed to execute
-
stat
Retrieve file/directory handle meta-data- Parameters:
handle- TheSftpClient.Handleobtained via one of theopencalls- Returns:
- The associated
SftpClient.Attributes - Throws:
IOException- If failed to execute
-
setStat
Update remote node meta-data- Parameters:
path- The remote pathattributes- TheSftpClient.Attributesto update- Throws:
IOException- If failed to execute
-
setStat
Update remote node meta-data- Parameters:
handle- TheSftpClient.Handleobtained via one of theopencallsattributes- TheSftpClient.Attributesto update- Throws:
IOException- If failed to execute
-
readLink
Retrieve target of a link- Parameters:
path- Remote path that represents a link- Returns:
- The link target
- Throws:
IOException- If failed to execute
-
symLink
Create symbolic link- Parameters:
linkPath- The link locationtargetPath- The referenced target by the link- Throws:
IOException- If failed to execute- See Also:
-
link
Create a link- Parameters:
linkPath- The link locationtargetPath- The referenced target by the linksymbolic- Iftruethen make this a symbolic link, otherwise a hard one- Throws:
IOException- If failed to execute
-
lock
- Throws:
IOException
-
unlock
- Throws:
IOException
-
openRemotePathChannel
- Throws:
IOException
-
openRemotePathChannel
default FileChannel openRemotePathChannel(String path, Collection<? extends OpenOption> options) throws IOException - Throws:
IOException
-
openRemoteFileChannel
default FileChannel openRemoteFileChannel(String path, SftpClient.OpenMode... modes) throws IOException - Throws:
IOException
-
openRemoteFileChannel
FileChannel openRemoteFileChannel(String path, Collection<SftpClient.OpenMode> modes) throws IOException Opens anFileChannelon the specified remote path- Parameters:
path- The remote pathmodes- The access mode(s) - ifnull/empty then theDEFAULT_CHANNEL_MODESare used- Returns:
- The open
FileChannel- 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. - Throws:
IOException- If failed to open the channel- See Also:
-
readDir
- Parameters:
path- The remote directory path- Returns:
- An
Iterablethat can be used to iterate over all the directory entries (unlikereadDir(Handle)) - Throws:
IOException- If failed to access the remote site- See Also:
-
readEntries
Reads all entries available for a directory- Parameters:
path- Remote directory path- Returns:
- A
Collectionof all the entries in the remote directory - Throws:
IOException- If failed to retrieve the entries- See Also:
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
default InputStream read(String path, int bufferSize, SftpClient.OpenMode... mode) throws IOException - Throws:
IOException
-
read
- Throws:
IOException
-
read
InputStream read(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException Read a remote file's data via an input stream- Parameters:
path- The remote file pathbufferSize- The internal read buffer sizemode- The remote fileSftpClient.OpenModes- Returns:
- An
InputStreamfor reading the remote file data - Throws:
IOException- If failed to execute
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
default OutputStream write(String path, int bufferSize, SftpClient.OpenMode... mode) throws IOException - Throws:
IOException
-
write
- Throws:
IOException
-
write
OutputStream write(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException Write to a remote file via an output stream- Parameters:
path- The remote file pathbufferSize- The internal write buffer sizemode- The remote fileSftpClient.OpenModes- Returns:
- An
OutputStreamfor writing the data - Throws:
IOException- If failed to execute
-
getExtension
- Type Parameters:
E- The generic extension type- Parameters:
extensionType- The extension type- Returns:
- The extension instance - Note: it is up to the caller to invoke
OptionalFeature.isSupported()-nullif this extension type is not implemented by the client - See Also:
-
getExtension
- Parameters:
extensionName- The extension name- Returns:
- The extension instance - Note: it is up to the caller to invoke
OptionalFeature.isSupported()-nullif this extension type is not implemented by the client - See Also:
-
getExtension
- Parameters:
factory- TheSftpClientExtensionFactoryinstance to use - ignored ifnull- Returns:
- The extension instance - Note: it is up to the caller to invoke
OptionalFeature.isSupported()-nullif this extension type is not implemented by the client
-
singleSessionInstance
Creates anSftpClientinstance that also closes the underlyingclient sessionwhen the client instance is closed.- Returns:
- The wrapper instance
-