Package org.apache.sshd.common.scp
Class ScpHelper
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.scp.ScpHelper
-
- All Implemented Interfaces:
SessionContextHolder
,SessionHolder<Session>
public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Session>
- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_COPY_BUFFER_SIZE
Default size (in bytes) of send / receive buffer sizestatic String
DEFAULT_DIR_OCTAL_PERMISSIONS
static String
DEFAULT_FILE_OCTAL_PERMISSIONS
static int
DEFAULT_RECEIVE_BUFFER_SIZE
static int
DEFAULT_SEND_BUFFER_SIZE
static int
ERROR
protected FileSystem
fileSystem
protected InputStream
in
protected ScpTransferEventListener
listener
static int
MIN_COPY_BUFFER_SIZE
The minimum size for sending / receiving filesstatic int
MIN_RECEIVE_BUFFER_SIZE
static int
MIN_SEND_BUFFER_SIZE
static int
OK
protected ScpFileOpener
opener
protected OutputStream
out
static int
S_IRGRP
static int
S_IROTH
static int
S_IRUSR
static int
S_IWGRP
static int
S_IWOTH
static int
S_IWUSR
static int
S_IXGRP
static int
S_IXOTH
static int
S_IXUSR
static String
SCP_COMMAND_PREFIX
Command prefix used to identify SCP commandsstatic int
WARNING
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ScpHelper(Session session, InputStream in, OutputStream out, FileSystem fileSystem, ScpFileOpener opener, ScpTransferEventListener eventListener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
ack()
static String
getExitStatusName(Integer exitStatus)
static String
getOctalPermissions(Collection<PosixFilePermission> perms)
Session
getSession()
static Set<PosixFilePermission>
parseOctalPermissions(String str)
int
readAck(boolean canEof)
String
readLine()
String
readLine(boolean canEof)
void
receive(Path local, boolean recursive, boolean shouldBeDir, boolean preserve, int bufferSize)
protected void
receive(ScpReceiveLineHandler handler)
void
receiveDir(String header, Path local, ScpTimestamp time, boolean preserve, int bufferSize)
void
receiveFile(String header, Path local, ScpTimestamp time, boolean preserve, int bufferSize)
void
receiveFileStream(OutputStream local, int bufferSize)
void
receiveStream(String header, ScpTargetStreamResolver resolver, ScpTimestamp time, boolean preserve, int bufferSize)
Path
resolveLocalPath(String commandPath)
Path
resolveLocalPath(String basedir, String subpath)
protected void
send(Path local, boolean recursive, boolean preserve, int bufferSize, LinkOption... options)
void
send(Collection<String> paths, boolean recursive, boolean preserve, int bufferSize)
void
sendDir(Path local, boolean preserve, int bufferSize)
protected void
sendError(String message)
static <O extends OutputStream>
OsendError(O out, String message)
void
sendFile(Path local, boolean preserve, int bufferSize)
void
sendPaths(Collection<? extends Path> paths, boolean recursive, boolean preserve, int bufferSize)
protected void
sendResponseMessage(int level, String message)
static <O extends OutputStream>
OsendResponseMessage(O out, int level, String message)
void
sendStream(ScpSourceStreamResolver resolver, boolean preserve, int bufferSize)
protected void
sendWarning(String message)
static <O extends OutputStream>
OsendWarning(O out, String message)
String
toString()
protected void
validateAckReplyCode(String command, Object location, int replyCode, boolean eofAllowed)
protected void
validateCommandStatusCode(String command, Object location, int statusCode, boolean eofAllowed)
protected void
validateOperationReadyCode(String command, Object location, int readyCode, boolean eofAllowed)
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
SCP_COMMAND_PREFIX
public static final String SCP_COMMAND_PREFIX
Command prefix used to identify SCP commands- See Also:
- Constant Field Values
-
OK
public static final int OK
- See Also:
- Constant Field Values
-
WARNING
public static final int WARNING
- See Also:
- Constant Field Values
-
ERROR
public static final int ERROR
- See Also:
- Constant Field Values
-
DEFAULT_COPY_BUFFER_SIZE
public static final int DEFAULT_COPY_BUFFER_SIZE
Default size (in bytes) of send / receive buffer size- See Also:
- Constant Field Values
-
DEFAULT_RECEIVE_BUFFER_SIZE
public static final int DEFAULT_RECEIVE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_SEND_BUFFER_SIZE
public static final int DEFAULT_SEND_BUFFER_SIZE
- See Also:
- Constant Field Values
-
MIN_COPY_BUFFER_SIZE
public static final int MIN_COPY_BUFFER_SIZE
The minimum size for sending / receiving files- See Also:
- Constant Field Values
-
MIN_RECEIVE_BUFFER_SIZE
public static final int MIN_RECEIVE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
MIN_SEND_BUFFER_SIZE
public static final int MIN_SEND_BUFFER_SIZE
- See Also:
- Constant Field Values
-
S_IRUSR
public static final int S_IRUSR
- See Also:
- Constant Field Values
-
S_IWUSR
public static final int S_IWUSR
- See Also:
- Constant Field Values
-
S_IXUSR
public static final int S_IXUSR
- See Also:
- Constant Field Values
-
S_IRGRP
public static final int S_IRGRP
- See Also:
- Constant Field Values
-
S_IWGRP
public static final int S_IWGRP
- See Also:
- Constant Field Values
-
S_IXGRP
public static final int S_IXGRP
- See Also:
- Constant Field Values
-
S_IROTH
public static final int S_IROTH
- See Also:
- Constant Field Values
-
S_IWOTH
public static final int S_IWOTH
- See Also:
- Constant Field Values
-
S_IXOTH
public static final int S_IXOTH
- See Also:
- Constant Field Values
-
DEFAULT_DIR_OCTAL_PERMISSIONS
public static final String DEFAULT_DIR_OCTAL_PERMISSIONS
- See Also:
- Constant Field Values
-
DEFAULT_FILE_OCTAL_PERMISSIONS
public static final String DEFAULT_FILE_OCTAL_PERMISSIONS
- See Also:
- Constant Field Values
-
in
protected final InputStream in
-
out
protected final OutputStream out
-
fileSystem
protected final FileSystem fileSystem
-
opener
protected final ScpFileOpener opener
-
listener
protected final ScpTransferEventListener listener
-
-
Constructor Detail
-
ScpHelper
public ScpHelper(Session session, InputStream in, OutputStream out, FileSystem fileSystem, ScpFileOpener opener, ScpTransferEventListener eventListener)
-
-
Method Detail
-
getSession
public Session getSession()
- Specified by:
getSession
in interfaceSessionHolder<Session>
-
receiveFileStream
public void receiveFileStream(OutputStream local, int bufferSize) throws IOException
- Throws:
IOException
-
receive
public void receive(Path local, boolean recursive, boolean shouldBeDir, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
receive
protected void receive(ScpReceiveLineHandler handler) throws IOException
- Throws:
IOException
-
receiveDir
public void receiveDir(String header, Path local, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
receiveFile
public void receiveFile(String header, Path local, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
receiveStream
public void receiveStream(String header, ScpTargetStreamResolver resolver, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Throws:
IOException
-
readLine
public String readLine(boolean canEof) throws IOException
- Throws:
IOException
-
send
public void send(Collection<String> paths, boolean recursive, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
sendPaths
public void sendPaths(Collection<? extends Path> paths, boolean recursive, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
send
protected void send(Path local, boolean recursive, boolean preserve, int bufferSize, LinkOption... options) throws IOException
- Throws:
IOException
-
resolveLocalPath
public Path resolveLocalPath(String basedir, String subpath) throws IOException
- Throws:
IOException
-
resolveLocalPath
public Path resolveLocalPath(String commandPath) throws IOException, InvalidPathException
- Parameters:
commandPath
- 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
-
sendFile
public void sendFile(Path local, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
sendStream
public void sendStream(ScpSourceStreamResolver resolver, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
validateOperationReadyCode
protected void validateOperationReadyCode(String command, Object location, int readyCode, boolean eofAllowed) throws IOException
- Throws:
IOException
-
validateAckReplyCode
protected void validateAckReplyCode(String command, Object location, int replyCode, boolean eofAllowed) throws IOException
- Throws:
IOException
-
validateCommandStatusCode
protected void validateCommandStatusCode(String command, Object location, int statusCode, boolean eofAllowed) throws IOException
- Throws:
IOException
-
sendDir
public void sendDir(Path local, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
getOctalPermissions
public static String getOctalPermissions(Collection<PosixFilePermission> perms)
-
parseOctalPermissions
public static Set<PosixFilePermission> parseOctalPermissions(String str)
-
sendWarning
protected void sendWarning(String message) throws IOException
- Throws:
IOException
-
sendError
protected void sendError(String message) throws IOException
- Throws:
IOException
-
sendResponseMessage
protected void sendResponseMessage(int level, String message) throws IOException
- Throws:
IOException
-
sendWarning
public static <O extends OutputStream> O sendWarning(O out, String message) throws IOException
- Throws:
IOException
-
sendError
public static <O extends OutputStream> O sendError(O out, String message) throws IOException
- Throws:
IOException
-
sendResponseMessage
public static <O extends OutputStream> O sendResponseMessage(O out, int level, String message) throws IOException
- Throws:
IOException
-
ack
public void ack() throws IOException
- Throws:
IOException
-
readAck
public int readAck(boolean canEof) throws IOException
- Throws:
IOException
-
-