Package org.apache.sshd.common.scp
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...
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_AUTO_SYNC_FILE_ON_WRITE
Default value for "scp-auto-sync-on-write" if none setstatic java.lang.String
PROP_AUTO_SYNC_FILE_ON_WRITE
Whether to synchronize written file data with underlying file-system
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
closeRead(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.io.InputStream stream)
Called when the stream obtained fromopenRead
is no longer required since data has been successfully copied.default void
closeWrite(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.io.OutputStream os)
Called when output stream obtained fromopenWrite
is no longer needed since data copying has been successfully completed.ScpSourceStreamResolver
createScpSourceStreamResolver(Session session, java.nio.file.Path path)
ScpTargetStreamResolver
createScpTargetStreamResolver(Session session, java.nio.file.Path path)
default java.nio.file.attribute.BasicFileAttributes
getLocalBasicFileAttributes(Session session, java.nio.file.Path path, java.nio.file.LinkOption... options)
default java.util.Set<java.nio.file.attribute.PosixFilePermission>
getLocalFilePermissions(Session session, java.nio.file.Path path, java.nio.file.LinkOption... options)
default java.nio.file.DirectoryStream<java.nio.file.Path>
getLocalFolderChildren(Session session, java.nio.file.Path path)
Invoked when required to send all children of a local directorydefault java.lang.Iterable<java.nio.file.Path>
getMatchingFilesToSend(Session session, java.nio.file.Path basedir, java.lang.String pattern)
Invoked when required to send a pattern of filesjava.io.InputStream
openRead(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.nio.file.OpenOption... options)
Create an input stream to read from a filejava.io.OutputStream
openWrite(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.nio.file.OpenOption... options)
Create an output stream to write to a filedefault java.nio.file.Path
resolveIncomingFilePath(Session session, java.nio.file.Path localPath, java.lang.String name, boolean preserve, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, ScpTimestamp time)
Invoked when receiving a new file to via a directory commanddefault java.nio.file.Path
resolveIncomingReceiveLocation(Session session, java.nio.file.Path path, boolean recursive, boolean shouldBeDir, boolean preserve)
Invoked when a request to receive something is processeddefault java.nio.file.Path
resolveLocalPath(Session session, java.nio.file.FileSystem fileSystem, java.lang.String commandPath)
default java.nio.file.Path
resolveOutgoingFilePath(Session session, java.nio.file.Path localPath, java.nio.file.LinkOption... options)
Called when there is a candidate file/folder for sendingdefault boolean
sendAsDirectory(Session session, java.nio.file.Path path, java.nio.file.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, java.nio.file.Path path, java.nio.file.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(java.nio.file.Path file, java.util.Set<java.nio.file.attribute.PosixFilePermission> perms, ScpTimestamp time)
-
-
-
Field Detail
-
PROP_AUTO_SYNC_FILE_ON_WRITE
static final java.lang.String PROP_AUTO_SYNC_FILE_ON_WRITE
Whether to synchronize written file data with underlying file-system- See Also:
- Constant Field Values
-
DEFAULT_AUTO_SYNC_FILE_ON_WRITE
static final boolean DEFAULT_AUTO_SYNC_FILE_ON_WRITE
Default value for "scp-auto-sync-on-write" if none set- See Also:
- Constant Field Values
-
-
Method Detail
-
resolveIncomingFilePath
default java.nio.file.Path resolveIncomingFilePath(Session session, java.nio.file.Path localPath, java.lang.String name, boolean preserve, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, ScpTimestamp time) throws java.io.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 requestedScpTimestamp
- may benull
if nothing to update- Returns:
- The actual target file path for the incoming file/directory
- Throws:
java.io.IOException
- If failed to resolve the file path- See Also:
updateFileProperties
-
getMatchingFilesToSend
default java.lang.Iterable<java.nio.file.Path> getMatchingFilesToSend(Session session, java.nio.file.Path basedir, java.lang.String pattern) throws java.io.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- Returns:
- The matching relative paths of the children to send
- Throws:
java.io.IOException
- If failed to scan the directory
-
sendAsRegularFile
default boolean sendAsRegularFile(Session session, java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.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:
java.io.IOException
- If failed to decide
-
sendAsDirectory
default boolean sendAsDirectory(Session session, java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.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:
java.io.IOException
- If failed to decide
-
getLocalFolderChildren
default java.nio.file.DirectoryStream<java.nio.file.Path> getLocalFolderChildren(Session session, java.nio.file.Path path) throws java.io.IOException
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:
java.io.IOException
- If failed to provide the children stream- See Also:
sendAsDirectory
-
getLocalBasicFileAttributes
default java.nio.file.attribute.BasicFileAttributes getLocalBasicFileAttributes(Session session, java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
getLocalFilePermissions
default java.util.Set<java.nio.file.attribute.PosixFilePermission> getLocalFilePermissions(Session session, java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveLocalPath
default java.nio.file.Path resolveLocalPath(Session session, java.nio.file.FileSystem fileSystem, java.lang.String commandPath) throws java.io.IOException, java.nio.file.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:
java.io.IOException
- If failed to resolve the pathjava.nio.file.InvalidPathException
- If invalid local path value
-
resolveIncomingReceiveLocation
default java.nio.file.Path resolveIncomingReceiveLocation(Session session, java.nio.file.Path path, boolean recursive, boolean shouldBeDir, boolean preserve) throws java.io.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:
java.io.IOException
- If failed to resolve target location
-
resolveOutgoingFilePath
default java.nio.file.Path resolveOutgoingFilePath(Session session, java.nio.file.Path localPath, java.nio.file.LinkOption... options) throws java.io.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:
java.io.IOException
- If failed to resolve
-
openRead
java.io.InputStream openRead(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.nio.file.OpenOption... options) throws java.io.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:
java.io.IOException
- If failed to open the file
-
closeRead
default void closeRead(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.io.InputStream stream) throws java.io.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:
java.io.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, java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
openWrite
java.io.OutputStream openWrite(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.nio.file.OpenOption... options) throws java.io.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:
java.io.IOException
- If failed to open the file
-
closeWrite
default void closeWrite(Session session, java.nio.file.Path file, long size, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, java.io.OutputStream os) throws java.io.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:
java.io.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, java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
updateFileProperties
static void updateFileProperties(java.nio.file.Path file, java.util.Set<java.nio.file.attribute.PosixFilePermission> perms, ScpTimestamp time) throws java.io.IOException
- Throws:
java.io.IOException
-
-