Top Description Methods
org.apache.sshd.scp.common

public Interface ScpFileOpener

Known Direct Implementers
org.apache.sshd.scp.common.helpers.DefaultScpFileOpener
Imports
java.io.File, .FileNotFoundException, .IOException, .InputStream, .OutputStream, java.nio.file.AccessDeniedException, .DirectoryStream, .FileSystem, .Files, .InvalidPathException, .LinkOption, .OpenOption, .Path, java.nio.file.attribute.BasicFileAttributeView, .BasicFileAttributes, .FileTime, .PosixFilePermission, java.util.Collections, .Set, java.util.concurrent.TimeUnit, org.apache.sshd.common.SshException, org.apache.sshd.common.session.Session, org.apache.sshd.common.util.GenericUtils, .OsUtils, .SelectorUtils, org.apache.sshd.common.util.io.DirectoryScanner, .IoUtils, org.apache.sshd.scp.common.helpers.ScpTimestampCommandDetails

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...
Author
Apache MINA SSHD Project

Method Summary

Modifier and TypeMethod and Description
public default void
closeRead(Session
The Session requesting the access
session
,
Path
The requested local file Path
file
,
long
The expected transfer bytes count
size
,
Set<PosixFilePermission>
The requested file permissions
permissions
,
InputStream
The InputStream to close
stream
)

Called when the stream obtained from openRead is no longer required since data has been successfully copied.

public default void
closeWrite(Session
The Session requesting the access
session
,
Path
The requested local file Path
file
,
long
The expected transfer byte count
size
,
Set<PosixFilePermission>
The requested file permissions
permissions
,
OutputStream
The opened OutputStream
os
)

Called when output stream obtained from openWrite is no longer needed since data copying has been successfully completed.

public ScpSourceStreamResolver
public ScpTargetStreamResolver
public default BasicFileAttributes
public default Set<PosixFilePermission>
getLocalFilePermissions(Session session, Path path, LinkOption... options)

public default DirectoryStream<Path>

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 respective sendAsRegularFile and sendAsDirectory methods
getLocalFolderChildren
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The local folder Path
path
)

Invoked when required to send all children of a local directory

public default Iterable<Path>

Returns:

The matching relative paths of the children to send
getMatchingFilesToSend
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The base directory - may be null/empty to indicate CWD
basedir
,
String
The required pattern - ignored if null/empty - returns empty result
pattern
)

Invoked when required to send a pattern of files

public InputStream

Returns:

The open InputStream never null
openRead
(Session
The Session requesting the access
session
,
Path
The requested local file Path
file
,
long
The expected transfer bytes count
size
,
Set<PosixFilePermission>
The requested file permissions
permissions
,
OpenOption...
The OpenOptions - may be null/empty
options
)

Create an input stream to read from a file

public OutputStream

Returns:

The open OutputStream never null
openWrite
(Session
The Session requesting the access
session
,
Path
The requested local file Path
file
,
long
The expected transfer byte count
size
,
Set<PosixFilePermission>
The requested file permissions
permissions
,
OpenOption...
The OpenOptions - may be null/empty
options
)

Create an output stream to write to a file

public default Path

Returns:

The actual target file path for the incoming file/directory
resolveIncomingFilePath
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The target local path
localPath
,
String
The target file name
name
,
boolean
Whether requested to preserve the permissions and timestamp
preserve
,
Set<PosixFilePermission>
The requested file permissions
permissions
,
ScpTimestampCommandDetails
The requested ScpTimestampCommandDetails - may be null if nothing to update
time
)

Invoked when receiving a new file to via a directory command

public default Path

Returns:

The effective target path - default=same as input
resolveIncomingReceiveLocation
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The local target Path of the request
path
,
boolean
Whether the request is recursive
recursive
,
boolean
Whether target path is expected to be a directory
shouldBeDir
,
boolean
Whether target path is expected to preserve attributes (permissions, times)
preserve
)

Invoked when a request to receive something is processed

public default Path

Returns:

The resolved absolute and normalized local Path
resolveLocalPath
(Session
The client/server Session through which the transfer is being executed
session
,
FileSystem
The local FileSystem on which local file should reside
fileSystem
,
String
The command path using the local file separator
commandPath
)

public default Path

Returns:

The effective outgoing file path (default=same as input)
resolveOutgoingFilePath
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The original file/folder Path for sending
localPath
,
LinkOption...
The LinkOption-s to use for validation
options
)

Called when there is a candidate file/folder for sending

public default boolean

Returns:

Whether to send the file as a directory - Note: if true then getLocalFolderChildren(Session, Path) is consulted
sendAsDirectory
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The local Path
path
,
LinkOption... options)

Invoked on a local path in order to decide whether it should be sent as a file or as a directory

public default boolean

Returns:

Whether to send the file as a regular one - Note: if false then the sendAsDirectory(Session, Path, LinkOption...) is consulted.
sendAsRegularFile
(Session
The client/server Session through which the transfer is being executed
session
,
Path
The local Path
path
,
LinkOption... options)

Invoked on a local path in order to decide whether it should be sent as a file or as a directory

public static void

Method Detail

closeReadback to summary
public default void closeRead(Session session, Path file, long size, Set<PosixFilePermission> permissions, InputStream stream) throws IOException

Called when the stream obtained from openRead is no longer required since data has been successfully copied.

Parameters
session:Session

The Session requesting the access

file:Path

The requested local file Path

size:long

The expected transfer bytes count

permissions:Set<PosixFilePermission>

The requested file permissions

stream:InputStream

The InputStream to close

Exceptions
IOException:
If failed to close the stream - Note: stream will be closed regardless of whether this method throws an exception or not.
closeWriteback to summary
public default void closeWrite(Session session, Path file, long size, Set<PosixFilePermission> permissions, OutputStream os) throws IOException

Called when output stream obtained from openWrite is no longer needed since data copying has been successfully completed.

Parameters
session:Session

The Session requesting the access

file:Path

The requested local file Path

size:long

The expected transfer byte count

permissions:Set<PosixFilePermission>

The requested file permissions

os:OutputStream

The opened OutputStream

Exceptions
IOException:
If failed to close the stream - Note: stream will be closed regardless of whether this method throws an exception or not.
createScpSourceStreamResolverback to summary
public ScpSourceStreamResolver createScpSourceStreamResolver(Session session, Path path) throws IOException
createScpTargetStreamResolverback to summary
public ScpTargetStreamResolver createScpTargetStreamResolver(Session session, Path path) throws IOException
getLocalBasicFileAttributesback to summary
public default BasicFileAttributes getLocalBasicFileAttributes(Session session, Path path, LinkOption... options) throws IOException
getLocalFilePermissionsback to summary
public default Set<PosixFilePermission> getLocalFilePermissions(Session session, Path path, LinkOption... options) throws IOException
getLocalFolderChildrenback to summary
public default DirectoryStream<Path> getLocalFolderChildren(Session session, Path path) throws IOException

Invoked when required to send all children of a local directory

Parameters
session:Session

The client/server Session through which the transfer is being executed

path:Path

The local folder Path

Returns:DirectoryStream<Path>

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 respective sendAsRegularFile and sendAsDirectory methods

Exceptions
IOException:
If failed to provide the children stream
See Also
sendAsDirectory
getMatchingFilesToSendback to summary
public default Iterable<Path> getMatchingFilesToSend(Session session, Path basedir, String pattern) throws IOException

Invoked when required to send a pattern of files

Parameters
session:Session

The client/server Session through which the transfer is being executed

basedir:Path

The base directory - may be null/empty to indicate CWD

pattern:String

The required pattern - ignored if null/empty - returns empty result

Returns:Iterable<Path>

The matching relative paths of the children to send

Exceptions
IOException:
If failed to scan the directory
openReadback to summary
public 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:Session

The Session requesting the access

file:Path

The requested local file Path

size:long

The expected transfer bytes count

permissions:Set<PosixFilePermission>

The requested file permissions

options:OpenOption[]

The OpenOptions - may be null/empty

Returns:InputStream

The open InputStream never null

Exceptions
IOException:
If failed to open the file
openWriteback to summary
public 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:Session

The Session requesting the access

file:Path

The requested local file Path

size:long

The expected transfer byte count

permissions:Set<PosixFilePermission>

The requested file permissions

options:OpenOption[]

The OpenOptions - may be null/empty

Returns:OutputStream

The open OutputStream never null

Exceptions
IOException:
If failed to open the file
resolveIncomingFilePathback to summary
public 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:Session

The client/server Session through which the transfer is being executed

localPath:Path

The target local path

name:String

The target file name

preserve:boolean

Whether requested to preserve the permissions and timestamp

permissions:Set<PosixFilePermission>

The requested file permissions

time:ScpTimestampCommandDetails

The requested ScpTimestampCommandDetails - may be null if nothing to update

Returns:Path

The actual target file path for the incoming file/directory

Exceptions
IOException:
If failed to resolve the file path
See Also
updateFileProperties
resolveIncomingReceiveLocationback to summary
public 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:Session

The client/server Session through which the transfer is being executed

path:Path

The local target Path of the request

recursive:boolean

Whether the request is recursive

shouldBeDir:boolean

Whether target path is expected to be a directory

preserve:boolean

Whether target path is expected to preserve attributes (permissions, times)

Returns:Path

The effective target path - default=same as input

Exceptions
IOException:
If failed to resolve target location
resolveLocalPathback to summary
public default Path resolveLocalPath(Session session, FileSystem fileSystem, String commandPath) throws IOException, InvalidPathException
Parameters
session:Session

The client/server Session through which the transfer is being executed

fileSystem:FileSystem

The local FileSystem on which local file should reside

commandPath:String

The command path using the local file separator

Returns:Path

The resolved absolute and normalized local Path

Exceptions
IOException:
If failed to resolve the path
InvalidPathException:
If invalid local path value
resolveOutgoingFilePathback to summary
public default Path resolveOutgoingFilePath(Session session, Path localPath, LinkOption... options) throws IOException

Called when there is a candidate file/folder for sending

Parameters
session:Session

The client/server Session through which the transfer is being executed

localPath:Path

The original file/folder Path for sending

options:LinkOption[]

The LinkOption-s to use for validation

Returns:Path

The effective outgoing file path (default=same as input)

Exceptions
IOException:
If failed to resolve
sendAsDirectoryback to summary
public 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:Session

The client/server Session through which the transfer is being executed

path:Path

The local Path

options:LinkOption[]

The LinkOption-s

Returns:boolean

Whether to send the file as a directory - Note: if true then getLocalFolderChildren(Session, Path) is consulted

Exceptions
IOException:
If failed to decide
sendAsRegularFileback to summary
public 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:Session

The client/server Session through which the transfer is being executed

path:Path

The local Path

options:LinkOption[]

The LinkOption-s

Returns:boolean

Whether to send the file as a regular one - Note: if false then the sendAsDirectory(Session, Path, LinkOption...) is consulted.

Exceptions
IOException:
If failed to decide
updateFilePropertiesback to summary
public static void updateFileProperties(Path file, Set<PosixFilePermission> perms, ScpTimestampCommandDetails time) throws IOException