Package org.apache.sshd.scp.common
Interface ScpFileOpener
- All Known Implementing Classes:
DefaultScpFileOpener
public interface ScpFileOpener
Plug-in mechanism for users to intervene in the SCP process - e.g., apply some kind of traffic shaping mechanism,
display upload/download progress, etc...
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
closeRead
(Session session, Path file, long size, Set<PosixFilePermission> permissions, InputStream stream) Called when the stream obtained fromopenRead
is no longer required since data has been successfully copied.default void
closeWrite
(Session session, Path file, long size, Set<PosixFilePermission> permissions, OutputStream os) Called when output stream obtained fromopenWrite
is no longer needed since data copying has been successfully completed.createScpSourceStreamResolver
(Session session, Path path) createScpTargetStreamResolver
(Session session, Path path) default BasicFileAttributes
getLocalBasicFileAttributes
(Session session, Path path, LinkOption... options) default Set<PosixFilePermission>
getLocalFilePermissions
(Session session, Path path, LinkOption... options) default DirectoryStream<Path>
getLocalFolderChildren
(Session session, Path path) Invoked when required to send all children of a local directorygetMatchingFilesToSend
(Session session, Path basedir, String pattern) Invoked when required to send a pattern of filesopenRead
(Session session, Path file, long size, Set<PosixFilePermission> permissions, OpenOption... options) Create an input stream to read from a fileopenWrite
(Session session, Path file, long size, Set<PosixFilePermission> permissions, OpenOption... options) Create an output stream to write to a filedefault Path
resolveIncomingFilePath
(Session session, Path localPath, String name, boolean preserve, Set<PosixFilePermission> permissions, ScpTimestampCommandDetails time) Invoked when receiving a new file to via a directory commanddefault Path
resolveIncomingReceiveLocation
(Session session, Path path, boolean recursive, boolean shouldBeDir, boolean preserve) Invoked when a request to receive something is processeddefault Path
resolveLocalPath
(Session session, FileSystem fileSystem, String commandPath) default Path
resolveOutgoingFilePath
(Session session, Path localPath, LinkOption... options) Called when there is a candidate file/folder for sendingdefault boolean
sendAsDirectory
(Session session, Path path, LinkOption... options) Invoked on a local path in order to decide whether it should be sent as a file or as a directorydefault boolean
sendAsRegularFile
(Session session, Path path, LinkOption... options) Invoked on a local path in order to decide whether it should be sent as a file or as a directorystatic void
updateFileProperties
(Path file, Set<PosixFilePermission> perms, ScpTimestampCommandDetails time)
-
Method Details
-
resolveIncomingFilePath
default Path resolveIncomingFilePath(Session session, Path localPath, String name, boolean preserve, Set<PosixFilePermission> permissions, ScpTimestampCommandDetails time) throws IOException Invoked when receiving a new file to via a directory command- Parameters:
session
- The client/serverSession
through which the transfer is being executedlocalPath
- The target local pathname
- The target file namepreserve
- Whether requested to preserve the permissions and timestamppermissions
- The requested file permissionstime
- The requestedScpTimestampCommandDetails
- may benull
if nothing to update- Returns:
- The actual target file path for the incoming file/directory
- Throws:
IOException
- If failed to resolve the file path- See Also:
-
getMatchingFilesToSend
default Iterable<Path> getMatchingFilesToSend(Session session, Path basedir, String pattern) throws IOException Invoked when required to send a pattern of files- Parameters:
session
- The client/serverSession
through which the transfer is being executedbasedir
- The base directory - may benull
/empty to indicate CWDpattern
- The required pattern - ignored ifnull
/empty - returns empty result- Returns:
- The matching relative paths of the children to send
- Throws:
IOException
- If failed to scan the directory
-
sendAsRegularFile
default boolean sendAsRegularFile(Session session, Path path, LinkOption... options) throws IOException Invoked on a local path in order to decide whether it should be sent as a file or as a directory- Parameters:
session
- The client/serverSession
through which the transfer is being executedpath
- The localPath
options
- TheLinkOption
-s- Returns:
- Whether to send the file as a regular one - Note: if
false
then thesendAsDirectory(Session, Path, LinkOption...)
is consulted. - Throws:
IOException
- If failed to decide
-
sendAsDirectory
default boolean sendAsDirectory(Session session, Path path, LinkOption... options) throws IOException Invoked on a local path in order to decide whether it should be sent as a file or as a directory- Parameters:
session
- The client/serverSession
through which the transfer is being executedpath
- The localPath
options
- TheLinkOption
-s- Returns:
- Whether to send the file as a directory - Note: if
true
thengetLocalFolderChildren(Session, Path)
is consulted - Throws:
IOException
- If failed to decide
-
getLocalFolderChildren
Invoked when required to send all children of a local directory- Parameters:
session
- The client/serverSession
through which the transfer is being executedpath
- The local folderPath
- Returns:
- The
DirectoryStream
of children to send - Note: for each child the decision whether to send it as a file or a directory will be reached by consulting the respectivesendAsRegularFile
andsendAsDirectory
methods - Throws:
IOException
- If failed to provide the children stream- See Also:
-
getLocalBasicFileAttributes
default BasicFileAttributes getLocalBasicFileAttributes(Session session, Path path, LinkOption... options) throws IOException - Throws:
IOException
-
getLocalFilePermissions
default Set<PosixFilePermission> getLocalFilePermissions(Session session, Path path, LinkOption... options) throws IOException - Throws:
IOException
-
resolveLocalPath
default Path resolveLocalPath(Session session, FileSystem fileSystem, String commandPath) throws IOException, InvalidPathException - Parameters:
session
- The client/serverSession
through which the transfer is being executedfileSystem
- The localFileSystem
on which local file should residecommandPath
- The command path using the local file separator- Returns:
- The resolved absolute and normalized local
Path
- Throws:
IOException
- If failed to resolve the pathInvalidPathException
- If invalid local path value
-
resolveIncomingReceiveLocation
default Path resolveIncomingReceiveLocation(Session session, Path path, boolean recursive, boolean shouldBeDir, boolean preserve) throws IOException Invoked when a request to receive something is processed- Parameters:
session
- The client/serverSession
through which the transfer is being executedpath
- The local targetPath
of the requestrecursive
- Whether the request is recursiveshouldBeDir
- Whether target path is expected to be a directorypreserve
- Whether target path is expected to preserve attributes (permissions, times)- Returns:
- The effective target path - default=same as input
- Throws:
IOException
- If failed to resolve target location
-
resolveOutgoingFilePath
default Path resolveOutgoingFilePath(Session session, Path localPath, LinkOption... options) throws IOException Called when there is a candidate file/folder for sending- Parameters:
session
- The client/serverSession
through which the transfer is being executedlocalPath
- The original file/folderPath
for sendingoptions
- TheLinkOption
-s to use for validation- Returns:
- The effective outgoing file path (default=same as input)
- Throws:
IOException
- If failed to resolve
-
openRead
InputStream openRead(Session session, Path file, long size, Set<PosixFilePermission> permissions, OpenOption... options) throws IOException Create an input stream to read from a file- Parameters:
session
- TheSession
requesting the accessfile
- The requested local filePath
size
- The expected transfer bytes countpermissions
- The requested file permissionsoptions
- TheOpenOption
s - may benull
/empty- Returns:
- The open
InputStream
nevernull
- Throws:
IOException
- If failed to open the file
-
closeRead
default void closeRead(Session session, Path file, long size, Set<PosixFilePermission> permissions, InputStream stream) throws IOException Called when the stream obtained fromopenRead
is no longer required since data has been successfully copied.- Parameters:
session
- TheSession
requesting the accessfile
- The requested local filePath
size
- The expected transfer bytes countpermissions
- The requested file permissionsstream
- TheInputStream
to close- Throws:
IOException
- If failed to close the stream - Note: stream will be closed regardless of whether this method throws an exception or not.
-
createScpSourceStreamResolver
ScpSourceStreamResolver createScpSourceStreamResolver(Session session, Path path) throws IOException - Throws:
IOException
-
openWrite
OutputStream openWrite(Session session, Path file, long size, Set<PosixFilePermission> permissions, OpenOption... options) throws IOException Create an output stream to write to a file- Parameters:
session
- TheSession
requesting the accessfile
- The requested local filePath
size
- The expected transfer byte countpermissions
- The requested file permissionsoptions
- TheOpenOption
s - may benull
/empty- Returns:
- The open
OutputStream
nevernull
- Throws:
IOException
- If failed to open the file
-
closeWrite
default void closeWrite(Session session, Path file, long size, Set<PosixFilePermission> permissions, OutputStream os) throws IOException Called when output stream obtained fromopenWrite
is no longer needed since data copying has been successfully completed.- Parameters:
session
- TheSession
requesting the accessfile
- The requested local filePath
size
- The expected transfer byte countpermissions
- The requested file permissionsos
- The openedOutputStream
- Throws:
IOException
- If failed to close the stream - Note: stream will be closed regardless of whether this method throws an exception or not.
-
createScpTargetStreamResolver
ScpTargetStreamResolver createScpTargetStreamResolver(Session session, Path path) throws IOException - Throws:
IOException
-
updateFileProperties
static void updateFileProperties(Path file, Set<PosixFilePermission> perms, ScpTimestampCommandDetails time) throws IOException - Throws:
IOException
-