Class ScpHelper

    • Field Detail

      • SCP_COMMAND_PREFIX

        public static final java.lang.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
      • in

        protected final java.io.InputStream in
      • csIn

        protected final java.nio.charset.Charset csIn
      • out

        protected final java.io.OutputStream out
      • csOut

        protected final java.nio.charset.Charset csOut
      • fileSystem

        protected final java.nio.file.FileSystem fileSystem
      • sessionInstance

        private final Session sessionInstance
    • Constructor Detail

      • ScpHelper

        public ScpHelper​(Session session,
                         java.io.InputStream in,
                         java.nio.charset.Charset csIn,
                         java.io.OutputStream out,
                         java.nio.charset.Charset csOut,
                         java.nio.file.FileSystem fileSystem,
                         ScpFileOpener opener,
                         ScpTransferEventListener eventListener)
    • Method Detail

      • receiveFileStream

        public void receiveFileStream​(java.lang.String command,
                                      java.io.OutputStream local,
                                      int bufferSize)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • receive

        public void receive​(java.lang.String cmd,
                            java.nio.file.Path local,
                            boolean recursive,
                            boolean shouldBeDir,
                            boolean preserve,
                            int bufferSize)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • receive

        protected void receive​(java.lang.String cmd,
                               ScpReceiveLineHandler handler)
                        throws java.io.IOException
        Reads command line(s) and invokes the handler until EOF or and "E" command is received
        Parameters:
        cmd - The receive command being attempted
        handler - The ScpReceiveLineHandler to invoke when a command has been read
        Throws:
        java.io.IOException - If failed to read/write
      • receiveNextCmd

        protected ScpAckInfo receiveNextCmd()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • receiveDir

        public void receiveDir​(java.lang.String header,
                               java.nio.file.Path local,
                               ScpTimestampCommandDetails time,
                               boolean preserve,
                               int bufferSize)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • receiveFile

        public void receiveFile​(java.lang.String header,
                                java.nio.file.Path local,
                                ScpTimestampCommandDetails time,
                                boolean preserve,
                                int bufferSize)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readLine

        public java.lang.String readLine()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readLine

        public java.lang.String readLine​(boolean canEof)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • send

        public void send​(java.util.Collection<java.lang.String> paths,
                         boolean recursive,
                         boolean preserve,
                         int bufferSize)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • sendPaths

        public void sendPaths​(java.util.Collection<? extends java.nio.file.Path> paths,
                              boolean recursive,
                              boolean preserve,
                              int bufferSize)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • send

        protected void send​(java.nio.file.Path local,
                            boolean recursive,
                            boolean preserve,
                            int bufferSize,
                            java.nio.file.LinkOption... options)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • resolveLocalPath

        public java.nio.file.Path resolveLocalPath​(java.lang.String basedir,
                                                   java.lang.String subpath)
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • resolveLocalPath

        public java.nio.file.Path resolveLocalPath​(java.lang.String commandPath)
                                            throws java.io.IOException,
                                                   java.nio.file.InvalidPathException
        Parameters:
        commandPath - 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 path
        java.nio.file.InvalidPathException - If invalid local path value
      • sendFile

        public void sendFile​(java.nio.file.Path local,
                             boolean preserve,
                             int bufferSize)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • sendStream

        public void sendStream​(ScpSourceStreamResolver resolver,
                               boolean preserve,
                               int bufferSize)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • validateOperationReadyCode

        protected void validateOperationReadyCode​(java.lang.String command,
                                                  java.lang.Object location,
                                                  ScpAckInfo ackInfo)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • validateFileOperationAckReplyCode

        protected void validateFileOperationAckReplyCode​(java.lang.String command,
                                                         Session session,
                                                         ScpTransferEventListener.FileOperation op,
                                                         java.nio.file.Path file,
                                                         long fileSize,
                                                         java.util.Set<java.nio.file.attribute.PosixFilePermission> perms,
                                                         ScpAckInfo ackInfo)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • validateAckReplyCode

        protected void validateAckReplyCode​(java.lang.String command,
                                            java.lang.Object location,
                                            ScpAckInfo ackInfo)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • validateCommandStatusCode

        protected void validateCommandStatusCode​(java.lang.String command,
                                                 java.lang.Object location,
                                                 ScpAckInfo ackInfo,
                                                 boolean eofAllowed)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • sendDir

        public void sendDir​(java.nio.file.Path local,
                            boolean preserve,
                            int bufferSize)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • sendAcknowledgedCommand

        protected ScpAckInfo sendAcknowledgedCommand​(java.lang.String cmd)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • sendOk

        public void sendOk()
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • sendWarning

        protected void sendWarning​(java.lang.String message)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • sendError

        protected void sendError​(java.lang.String message)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • sendResponseMessage

        protected void sendResponseMessage​(int level,
                                           java.lang.String message)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readAck

        public ScpAckInfo readAck​(boolean canEof)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readAndValidateOperationAck

        public void readAndValidateOperationAck​(java.lang.String cmd,
                                                java.lang.Object location)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object