Package org.apache.sshd.scp.common
Class ScpHelper
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.scp.common.ScpHelper
-
- All Implemented Interfaces:
SessionContextHolder,SessionHolder<Session>
public class ScpHelper extends org.apache.sshd.common.util.logging.AbstractLoggingBean implements SessionHolder<Session>
- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected CharsetcsInprotected CharsetcsOutstatic intDEFAULT_COPY_BUFFER_SIZEDefault size (in bytes) of send / receive buffer sizestatic intDEFAULT_RECEIVE_BUFFER_SIZEstatic intDEFAULT_SEND_BUFFER_SIZEprotected FileSystemfileSystemprotected InputStreaminprotected ScpTransferEventListenerlistenerstatic intMIN_COPY_BUFFER_SIZEThe minimum size for sending / receiving filesstatic intMIN_RECEIVE_BUFFER_SIZEstatic intMIN_SEND_BUFFER_SIZEprotected ScpFileOpeneropenerprotected OutputStreamoutstatic StringSCP_COMMAND_PREFIXCommand prefix used to identify SCP commands
-
Constructor Summary
Constructors Constructor Description ScpHelper(Session session, InputStream in, OutputStream out, FileSystem fileSystem, ScpFileOpener opener, ScpTransferEventListener eventListener)ScpHelper(Session session, InputStream in, Charset csIn, OutputStream out, Charset csOut, FileSystem fileSystem, ScpFileOpener opener, ScpTransferEventListener eventListener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SessiongetSession()ScpAckInforeadAck(boolean canEof)StringreadLine()StringreadLine(boolean canEof)voidreceive(Path local, boolean recursive, boolean shouldBeDir, boolean preserve, int bufferSize)protected voidreceive(ScpReceiveLineHandler handler)Reads command line(s) and invokes the handler until EOF or and "E" command is receivedvoidreceiveDir(String header, Path local, ScpTimestampCommandDetails time, boolean preserve, int bufferSize)voidreceiveFile(String header, Path local, ScpTimestampCommandDetails time, boolean preserve, int bufferSize)voidreceiveFileStream(OutputStream local, int bufferSize)protected intreceiveNextCmd()voidreceiveStream(String header, ScpTargetStreamResolver resolver, ScpTimestampCommandDetails time, boolean preserve, int bufferSize)PathresolveLocalPath(String commandPath)PathresolveLocalPath(String basedir, String subpath)protected voidsend(Path local, boolean recursive, boolean preserve, int bufferSize, LinkOption... options)voidsend(Collection<String> paths, boolean recursive, boolean preserve, int bufferSize)protected ScpAckInfosendAcknowledgedCommand(String cmd)voidsendDir(Path local, boolean preserve, int bufferSize)protected voidsendError(String message)voidsendFile(Path local, boolean preserve, int bufferSize)voidsendOk()voidsendPaths(Collection<? extends Path> paths, boolean recursive, boolean preserve, int bufferSize)protected voidsendResponseMessage(int level, String message)voidsendStream(ScpSourceStreamResolver resolver, boolean preserve, int bufferSize)protected voidsendWarning(String message)StringtoString()protected voidvalidateAckReplyCode(String command, Object location, ScpAckInfo ackInfo)protected voidvalidateCommandStatusCode(String command, Object location, ScpAckInfo ackInfo, boolean eofAllowed)protected voidvalidateFileOperationAckReplyCode(String command, Session session, ScpTransferEventListener.FileOperation op, Path file, long fileSize, Set<PosixFilePermission> perms, ScpAckInfo ackInfo)protected voidvalidateOperationReadyCode(String command, Object location, ScpAckInfo ackInfo)-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
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
-
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
-
in
protected final InputStream in
-
csIn
protected final Charset csIn
-
out
protected final OutputStream out
-
csOut
protected final Charset csOut
-
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)
-
ScpHelper
public ScpHelper(Session session, InputStream in, Charset csIn, OutputStream out, Charset csOut, FileSystem fileSystem, ScpFileOpener opener, ScpTransferEventListener eventListener)
-
-
Method Detail
-
getSession
public Session getSession()
- Specified by:
getSessionin 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
Reads command line(s) and invokes the handler until EOF or and "E" command is received- Parameters:
handler- TheScpReceiveLineHandlerto invoke when a command has been read- Throws:
IOException- If failed to read/write
-
receiveNextCmd
protected int receiveNextCmd() throws IOException- Throws:
IOException
-
receiveDir
public void receiveDir(String header, Path local, ScpTimestampCommandDetails time, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
receiveFile
public void receiveFile(String header, Path local, ScpTimestampCommandDetails time, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
receiveStream
public void receiveStream(String header, ScpTargetStreamResolver resolver, ScpTimestampCommandDetails 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, ScpAckInfo ackInfo) throws IOException
- Throws:
IOException
-
validateFileOperationAckReplyCode
protected void validateFileOperationAckReplyCode(String command, Session session, ScpTransferEventListener.FileOperation op, Path file, long fileSize, Set<PosixFilePermission> perms, ScpAckInfo ackInfo) throws IOException
- Throws:
IOException
-
validateAckReplyCode
protected void validateAckReplyCode(String command, Object location, ScpAckInfo ackInfo) throws IOException
- Throws:
IOException
-
validateCommandStatusCode
protected void validateCommandStatusCode(String command, Object location, ScpAckInfo ackInfo, boolean eofAllowed) throws IOException
- Throws:
IOException
-
sendDir
public void sendDir(Path local, boolean preserve, int bufferSize) throws IOException
- Throws:
IOException
-
sendAcknowledgedCommand
protected ScpAckInfo sendAcknowledgedCommand(String cmd) throws IOException
- Throws:
IOException
-
sendOk
public void sendOk() throws IOException- Throws:
IOException
-
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
-
readAck
public ScpAckInfo readAck(boolean canEof) throws IOException
- Throws:
IOException
-
-