Package org.apache.sshd.scp.common
Interface ScpFileOpener
-
- All Known Implementing Classes:
DefaultScpFileOpener
public interface ScpFileOpenerPlug-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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidcloseRead(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 fromopenReadis no longer required since data has been successfully copied.default voidcloseWrite(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 fromopenWriteis no longer needed since data copying has been successfully completed.ScpSourceStreamResolvercreateScpSourceStreamResolver(Session session, java.nio.file.Path path)ScpTargetStreamResolvercreateScpTargetStreamResolver(Session session, java.nio.file.Path path)default java.nio.file.attribute.BasicFileAttributesgetLocalBasicFileAttributes(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.InputStreamopenRead(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.OutputStreamopenWrite(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.PathresolveIncomingFilePath(Session session, java.nio.file.Path localPath, java.lang.String name, boolean preserve, java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions, ScpTimestampCommandDetails time)Invoked when receiving a new file to via a directory commanddefault java.nio.file.PathresolveIncomingReceiveLocation(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.PathresolveLocalPath(Session session, java.nio.file.FileSystem fileSystem, java.lang.String commandPath)default java.nio.file.PathresolveOutgoingFilePath(Session session, java.nio.file.Path localPath, java.nio.file.LinkOption... options)Called when there is a candidate file/folder for sendingdefault booleansendAsDirectory(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 booleansendAsRegularFile(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 voidupdateFileProperties(java.nio.file.Path file, java.util.Set<java.nio.file.attribute.PosixFilePermission> perms, ScpTimestampCommandDetails time)
-
-
-
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, ScpTimestampCommandDetails time) throws java.io.IOException
Invoked when receiving a new file to via a directory command- Parameters:
session- The client/serverSessionthrough 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 benullif 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/serverSessionthrough 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:
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/serverSessionthrough which the transfer is being executedpath- The localPathoptions- TheLinkOption-s- Returns:
- Whether to send the file as a regular one - Note: if
falsethen 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/serverSessionthrough which the transfer is being executedpath- The localPathoptions- TheLinkOption-s- Returns:
- Whether to send the file as a directory - Note: if
truethengetLocalFolderChildren(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/serverSessionthrough which the transfer is being executedpath- The local folderPath- Returns:
- The
DirectoryStreamof 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 respectivesendAsRegularFileandsendAsDirectorymethods - 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/serverSessionthrough which the transfer is being executedfileSystem- The localFileSystemon 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/serverSessionthrough which the transfer is being executedpath- The local targetPathof 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/serverSessionthrough which the transfer is being executedlocalPath- The original file/folderPathfor 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- TheSessionrequesting the accessfile- The requested local filePathsize- The expected transfer bytes countpermissions- The requested file permissionsoptions- TheOpenOptions - may benull/empty- Returns:
- The open
InputStreamnevernull - 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 fromopenReadis no longer required since data has been successfully copied.- Parameters:
session- TheSessionrequesting the accessfile- The requested local filePathsize- The expected transfer bytes countpermissions- The requested file permissionsstream- TheInputStreamto 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- TheSessionrequesting the accessfile- The requested local filePathsize- The expected transfer byte countpermissions- The requested file permissionsoptions- TheOpenOptions - may benull/empty- Returns:
- The open
OutputStreamnevernull - 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 fromopenWriteis no longer needed since data copying has been successfully completed.- Parameters:
session- TheSessionrequesting the accessfile- The requested local filePathsize- 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, ScpTimestampCommandDetails time) throws java.io.IOException- Throws:
java.io.IOException
-
-