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 voidcloseRead(Session session, Path file, long size, Set<PosixFilePermission> permissions, InputStream stream) Called when the stream obtained fromopenReadis no longer required since data has been successfully copied.default voidcloseWrite(Session session, Path file, long size, Set<PosixFilePermission> permissions, OutputStream os) Called when output stream obtained fromopenWriteis no longer needed since data copying has been successfully completed.createScpSourceStreamResolver(Session session, Path path) createScpTargetStreamResolver(Session session, Path path) default BasicFileAttributesgetLocalBasicFileAttributes(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 PathresolveIncomingFilePath(Session session, Path localPath, String name, boolean preserve, Set<PosixFilePermission> permissions, ScpTimestampCommandDetails time) Invoked when receiving a new file to via a directory commanddefault PathresolveIncomingReceiveLocation(Session session, Path path, boolean recursive, boolean shouldBeDir, boolean preserve) Invoked when a request to receive something is processeddefault PathresolveLocalPath(Session session, FileSystem fileSystem, String commandPath) default PathresolveOutgoingFilePath(Session session, Path localPath, LinkOption... options) Called when there is a candidate file/folder for sendingdefault booleansendAsDirectory(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 booleansendAsRegularFile(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 voidupdateFileProperties(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/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:
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/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:
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/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:
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/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:
IOException- If failed to decide
-
getLocalFolderChildren
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:
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/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:
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/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:
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/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:
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- 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:
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 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:
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- 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:
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 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:
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
-