com.jscape.inet.scp

## Class Scp

- java.lang.Object
- - com.jscape.inet.scp.Scp

- All Implemented Interfaces:
    java.lang.AutoCloseable

      public class Scp
      extends java.lang.Object
      implements java.lang.AutoCloseable

  Implements the basic functionality of an SCP (Secure Copy) client over SSH2 protocol.

  Example Usage:

       // create new SshParamters instance
       SshParameters params = new SshParameters(hostname, username, password);

       // set key exchanges, ciphers, macs and compressions if needed
       SshConfiguration sshConfiguration = SshConfiguration.configurationFor(new ComponentClientKeyExchangeFactory(ClientKeyExchanges.DH_GROUP_SHA256, ClientKeyExchanges.DH_GROUP_SHA1),
                                                                            new JceEncryptionFactory(JceEncryptions.AES256_CBC, JceEncryptions.BLOWFISH_CBC),
                                                                            new JceMacFactory(JceMacs.HMAC_SHA2_512, JceMacs.HMAC_SHA1),
                                                                            new ComponentCompressionFactory(Compressions.NONE));

       // create new Scp instance
       Scp scp = new Scp(params, sshConfiguration);

       // register event listener
       scp.addListener(this);

       // establish connection
       scp.connect();

       // upload file to remote directory
       scp.upload(new File("c:/tmp/file.txt"),"/home/jsmith/");

       // disconnect
       scp.disconnect();

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_BUFFER_SIZE`
    `static java.io.File` | `DEFAULT_LOCAL_DIRECTORY`
    `static boolean` | `DEFAULT_PRESERVE_FILE_ATTRIBUTES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Scp(SshParameters parameters)` Creates a new SCP client instance.
    `Scp(SshParameters parameters, java.util.logging.Logger logger)` Creates a new SCP client instance.
    `Scp(SshParameters parameters, SshConfiguration configuration)` Creates a new SCP client instance.
    `Scp(SshParameters parameters, SshConfiguration configuration, java.io.File currentLocalDirectory, int transferBufferSizeBytes, boolean fileAttributesPreservingRequired, java.util.logging.Logger logger)` Creates a new SCP client instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addListener(ScpEventListener listener)` Adds an event listener.
    `void` | `close()`
    `Scp` | `connect()` Connects to the server.
    `void` | `disconnect()` Disconnects from the server.
    `void` | `download(java.io.OutputStream destinationStream, java.lang.String remoteDirectory, java.lang.String remoteFile)` Downloads a file.
    `java.io.File` | `download(java.lang.String remoteDirectory, java.lang.String remoteFile)` Downloads the file from SSH server.
    `java.io.File` | `download(java.lang.String remoteDirectory, java.lang.String remoteFile, java.io.File localFile)` Downloads a file.
    `void` | `downloadDir(java.lang.String remoteParentDirectory, java.lang.String remoteDirectory)` Downloads a directory recursively.
    `SshConfiguration` | `getConfiguration()` Returns current SSH configuration.
    `boolean` | `getDebug()` Returns debug mode flag.
    `java.io.PrintStream` | `getDebugStream()` Returns current debug stream if any.
    `int` | `getDownloadBlockSize()` Deprecated. getTransferBufferSizeBytes()
    `SshHostKeys` | `getHostKeys()` Returns SSH host keys for further use.
    `java.io.File` | `getLocalDir()` Returns current local directory.
    `java.util.logging.Level` | `getLogLevel()` Returns current log level.
    `SshParameters` | `getParameters()` Returns current SSH parameters.
    `boolean` | `getPreserveTime()` Deprecated. use isFileAttributesPreservingRequired
    `int` | `getTransferBufferSizeBytes()` Returns current transfer buffer size.
    `int` | `getUploadBlockSize()` Deprecated. use getTransferBufferSizeBytes()
    `void` | `interrupt()` Interrupts current transfer process.
    `boolean` | `isConnected()` Checks if client is connected.
    `boolean` | `isFileAttributesPreservingRequired()` Returns current file attributes preserving required flag.
    `void` | `mdownload(java.lang.String remoteDirectory, java.util.Collection<java.lang.String> remoteFiles)` Downloads multiple files.
    `void` | `mdownload(java.lang.String remoteDirectory, java.util.Enumeration<java.lang.String> remoteFiles)` Downloads multiple files.
    `void` | `mdownload(java.lang.String remoteDirectory, java.util.Iterator<java.lang.String> remoteFiles)` Downloads multiple files.
    `void` | `mdownload(java.lang.String remoteDirectory, java.lang.String... remoteFiles)` Downloads multiple files.
    `void` | `mdownload(java.lang.String remoteDirectory, java.lang.String wildcard)` Downloads multiple files matching filter from remote directory.
    `void` | `mupload(java.lang.String remoteDirectory, java.util.Collection<java.lang.String> localFiles)` Uploads multiple files taken from the current local directory.
    `void` | `mupload(java.lang.String remoteDirectory, java.util.Enumeration<java.lang.String> localFiles)` Uploads multiple files taken from the current local directory.
    `void` | `mupload(java.lang.String remoteDirectory, java.util.Iterator<java.lang.String> localFiles)` Uploads multiple files taken from the current local directory.
    `void` | `mupload(java.lang.String remoteDirectory, java.lang.String... localFiles)` Uploads multiple files taken from the current local directory.
    `void` | `mupload(java.lang.String remoteDirectory, java.lang.String regex)` Uploads multiple files matching the specified regular expression.
    `void` | `removeListener(ScpEventListener listener)` Removes an even listener.
    `void` | `setConfiguration(SshConfiguration value)` Sets current SSH configuration.
    `void` | `setDebug(boolean value)` Turns on/off debug log level.
    `void` | `setDebugStream(java.io.PrintStream value)` Sets a debug stream.
    `void` | `setDownloadBlockSize(int value)` Deprecated. use setTransferBufferSizeBytes()
    `void` | `setFileAttributesPreservingRequired(boolean value)` Sets file attributes preserving required flag.
    `void` | `setLocalDir(java.io.File value)` Sets current local directory.
    `void` | `setLogLevel(java.util.logging.Level level)` Sets current log level.
    `void` | `setParameters(SshParameters value)` Sets current SSH parameters.
    `void` | `setPreserveTime(boolean value)` Deprecated. use setFileAttributesPreservingRequired
    `void` | `setTransferBufferSizeBytes(int value)` Sets current transfer buffer size.
    `void` | `setUploadBlockSize(int value)` Deprecated. use setTransferBufferSizeBytes()
    `java.lang.String` | `toString()`
    `void` | `upload(byte[] sourceData, java.lang.String remoteDirectory, java.lang.String remoteFile)` Uploads data.
    `void` | `upload(java.io.File localFile, java.lang.String remoteDirectory)` Uploads a file.
    `void` | `upload(java.io.File localFile, java.lang.String remoteDirectory, java.lang.String remoteFile)` Uploads a file.
    `void` | `upload(java.io.InputStream sourceStream, long sourceLengthBytes, java.lang.String remoteDirectory, java.lang.String remoteFile)` Uploads data.
    `void` | `upload(java.io.InputStream sourceStream, java.lang.String remoteDirectory, java.lang.String remoteFile)` Uploads data.
    `void` | `upload(java.lang.String remoteDirectory, java.lang.String localFile)` Uploads a file.
    `void` | `upload(java.lang.String localFile, java.lang.String remoteDirectory, java.lang.String remoteFile)` Uploads a file.
    `void` | `uploadDir(java.io.File localDirectory, java.lang.String remoteParentDirectory)` Uploads a directory.
    `void` | `uploadDir(java.io.File localDirectory, java.lang.String remoteParentDirectory, java.lang.String remoteDirectory)` Uploads a directory.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_LOCAL_DIRECTORY

          public static final java.io.File DEFAULT_LOCAL_DIRECTORY

    - #### DEFAULT_BUFFER_SIZE

          public static final int DEFAULT_BUFFER_SIZE

      See Also:
        Constant Field Values

    - #### DEFAULT_PRESERVE_FILE_ATTRIBUTES

          public static final boolean DEFAULT_PRESERVE_FILE_ATTRIBUTES

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Scp

          public Scp(SshParameters parameters,
                     SshConfiguration configuration,
                     java.io.File currentLocalDirectory,
                     int transferBufferSizeBytes,
                     boolean fileAttributesPreservingRequired,
                     java.util.logging.Logger logger)

      Creates a new SCP client instance.
      Parameters:
        `parameters` - SSH connection parameters
        `configuration` - SSH configuration
        `currentLocalDirectory` - current local directory
        `transferBufferSizeBytes` - transfer buffer size in bytes
        `fileAttributesPreservingRequired` - file attributes preserving required flag
        `logger` - logger

    - #### Scp

          public Scp(SshParameters parameters,
                     SshConfiguration configuration)

      Creates a new SCP client instance.
      Parameters:
        `parameters` - SSH connection parameters
        `configuration` - SSH configuration

    - #### Scp

          public Scp(SshParameters parameters,
                     java.util.logging.Logger logger)

      Creates a new SCP client instance.
      Parameters:
        `parameters` - SSH connection parameters
        `logger` - logger

    - #### Scp

          public Scp(SshParameters parameters)

      Creates a new SCP client instance.
      Parameters:
        `parameters` - SSH connection parameters

  - ### Method Detail

    - #### getParameters

          public SshParameters getParameters()

      Returns current SSH parameters.
      Returns:
        SSH parameters

    - #### setParameters

          public void setParameters(SshParameters value)

      Sets current SSH parameters.
      Parameters:
        `value` - SSH parameters

    - #### getConfiguration

          public SshConfiguration getConfiguration()

      Returns current SSH configuration.
      Returns:
        SSH configuration

    - #### setConfiguration

          public void setConfiguration(SshConfiguration value)

      Sets current SSH configuration.
      Parameters:
        `value` - SSH configuration

    - #### getLocalDir

          public java.io.File getLocalDir()

      Returns current local directory.
      Returns:
        local directory

    - #### setLocalDir

          public void setLocalDir(java.io.File value)

      Sets current local directory.
      Parameters:
        `value` - local directory

    - #### getTransferBufferSizeBytes

          public int getTransferBufferSizeBytes()

      Returns current transfer buffer size.
      Returns:
        transfer buffer size in bytes

    - #### setTransferBufferSizeBytes

          public void setTransferBufferSizeBytes(int value)

      Sets current transfer buffer size.
      Parameters:
        `value` - transfer buffer size in bytes

    - #### getUploadBlockSize

          public int getUploadBlockSize()

      Deprecated. use getTransferBufferSizeBytes()
      Returns upload block size in bytes.
      Returns:
        upload block size in bytes

    - #### setUploadBlockSize

          public void setUploadBlockSize(int value)

      Deprecated. use setTransferBufferSizeBytes()
      Sets upload block size.
      Parameters:
        `value` - upload block size in bytes

    - #### getDownloadBlockSize

          public int getDownloadBlockSize()

      Deprecated. getTransferBufferSizeBytes()
      Returns download block size in bytes.
      Returns:
        download block size in bytes

    - #### setDownloadBlockSize

          public void setDownloadBlockSize(int value)

      Deprecated. use setTransferBufferSizeBytes()
      Sets download block size.
      Parameters:
        `value` - download block size in bytes

    - #### isFileAttributesPreservingRequired

          public boolean isFileAttributesPreservingRequired()

      Returns current file attributes preserving required flag.
      Returns:
        file attributes preserving required flag

    - #### setFileAttributesPreservingRequired

          public void setFileAttributesPreservingRequired(boolean value)

      Sets file attributes preserving required flag.
      Parameters:
        `value` - file attributes preserving required flag

    - #### getPreserveTime

          public boolean getPreserveTime()

      Deprecated. use isFileAttributesPreservingRequired
      Checks if preserve time flag is set.
      Returns:
        preserve flag value

    - #### setPreserveTime

          public void setPreserveTime(boolean value)

      Deprecated. use setFileAttributesPreservingRequired
      Sets preserver time flag.
      Parameters:
        `value` - preserve time

    - #### getLogLevel

          public java.util.logging.Level getLogLevel()

      Returns current log level.
      Returns:
        current log level

    - #### setLogLevel

          public void setLogLevel(java.util.logging.Level level)

      Sets current log level.
      Parameters:
        `level` - new log level

    - #### getDebug

          public boolean getDebug()

      Returns debug mode flag.
      Returns:
        `true` if debug mode is turned on

    - #### setDebug

          public void setDebug(boolean value)

      Turns on/off debug log level.
      Parameters:
        `value` - if `true` debug level will bw turned on

    - #### getDebugStream

          public java.io.PrintStream getDebugStream()

      Returns current debug stream if any.
      Returns:
        current debug stream

    - #### setDebugStream

          public void setDebugStream(java.io.PrintStream value)

      Sets a debug stream. Works only if DebugStreamLogger was set while instance creation.
      Parameters:
        `value` - debug stream

    - #### addListener

          public void addListener(ScpEventListener listener)

      Adds an event listener.
      Parameters:
        `listener` - event listener

    - #### removeListener

          public void removeListener(ScpEventListener listener)

      Removes an even listener.
      Parameters:
        `listener` - target listener

    - #### getHostKeys

          public SshHostKeys getHostKeys()

      Returns SSH host keys for further use.
      Returns:
        SSH host keys

    - #### connect

          public Scp connect()
                      throws ScpException

      Connects to the server.
      Throws:
        `ScpException` - if an error occurs

    - #### disconnect

          public void disconnect()

      Disconnects from the server.

    - #### close

          public void close()

      Specified by:
        `close` in interface `java.lang.AutoCloseable`

    - #### isConnected

          public boolean isConnected()

      Checks if client is connected.
      Returns:
        `true` if client is connected; `false` otherwise

    - #### interrupt

          public void interrupt()

      Interrupts current transfer process.

    - #### download

          public void download(java.io.OutputStream destinationStream,
                               java.lang.String remoteDirectory,
                               java.lang.String remoteFile)
                        throws java.io.IOException

      Downloads a file.
      Parameters:
        `destinationStream` - destination stream
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - source filename
      Throws:
        `java.io.IOException` - if an error occurs

    - #### download

          public java.io.File download(java.lang.String remoteDirectory,
                                       java.lang.String remoteFile,
                                       java.io.File localFile)
                                throws java.io.IOException

      Downloads a file.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - source filename
        `localFile` - destination file
      Returns:
        destination file
      Throws:
        `java.io.IOException` - if an error occurs

    - #### download

          public java.io.File download(java.lang.String remoteDirectory,
                                       java.lang.String remoteFile)
                                throws java.io.IOException

      Downloads the file from SSH server.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - source/destination filename
      Returns:
        destination file
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mdownload

          public void mdownload(java.lang.String remoteDirectory,
                                java.util.Collection<java.lang.String> remoteFiles)
                         throws java.io.IOException

      Downloads multiple files. Downloads are stored relative to current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFiles` - source file names
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mdownload

          public void mdownload(java.lang.String remoteDirectory,
                                java.lang.String... remoteFiles)
                         throws java.io.IOException

      Downloads multiple files. Downloads are stored relative to current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFiles` - source file names
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mdownload

          public void mdownload(java.lang.String remoteDirectory,
                                java.util.Enumeration<java.lang.String> remoteFiles)
                         throws java.io.IOException

      Downloads multiple files. Downloads are stored relative to current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFiles` - source file names
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mdownload

          public void mdownload(java.lang.String remoteDirectory,
                                java.util.Iterator<java.lang.String> remoteFiles)
                         throws java.io.IOException

      Downloads multiple files. Downloads are stored relative to current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFiles` - source file names
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mdownload

          public void mdownload(java.lang.String remoteDirectory,
                                java.lang.String wildcard)
                         throws java.io.IOException

      Downloads multiple files matching filter from remote directory. Downloads are stored relative to current local directory. Valid filters may indicate that a file name ends with a or starts with a given string.

      For example to download all files ending with the extension * .txt use the filter "*.txt". To download all files in the remote directory use the filter "*". To download all files that start with the string "file" use the filter "file*".
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `wildcard` - file filter wildcard
      Throws:
        `java.io.IOException` - if an error occurs

    - #### downloadDir

          public void downloadDir(java.lang.String remoteParentDirectory,
                                  java.lang.String remoteDirectory)
                           throws java.io.IOException

      Downloads a directory recursively.
      Parameters:
        `remoteParentDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteDirectory` - directory name
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(java.io.InputStream sourceStream,
                             long sourceLengthBytes,
                             java.lang.String remoteDirectory,
                             java.lang.String remoteFile)
                      throws java.io.IOException

      Uploads data.
      Parameters:
        `sourceStream` - source data stream
        `sourceLengthBytes` - total amount of data to upload in bytes
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - remote file name relative to parent remote directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(byte[] sourceData,
                             java.lang.String remoteDirectory,
                             java.lang.String remoteFile)
                      throws java.io.IOException

      Uploads data.
      Parameters:
        `sourceData` - source data array
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - remote file name relative to parent remote directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(java.io.InputStream sourceStream,
                             java.lang.String remoteDirectory,
                             java.lang.String remoteFile)
                      throws java.io.IOException

      Uploads data. This operation uses InputStream.available() for computing data amount to send. For data amount more than 2 Gb use Scp.upload(InputStream in, long dataLengthBytes, String remoteParentDirectory, String remoteFilename) method.
      Parameters:
        `sourceStream` - source data stream
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - remote file name relative to parent remote directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(java.io.File localFile,
                             java.lang.String remoteDirectory,
                             java.lang.String remoteFile)
                      throws java.io.IOException

      Uploads a file.
      Parameters:
        `localFile` - source file
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - remote file name relative to parent remote directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(java.io.File localFile,
                             java.lang.String remoteDirectory)
                      throws java.io.IOException

      Uploads a file.
      Parameters:
        `localFile` - source file
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(java.lang.String localFile,
                             java.lang.String remoteDirectory,
                             java.lang.String remoteFile)
                      throws java.io.IOException

      Uploads a file.
      Parameters:
        `localFile` - source file name
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteFile` - remote file name relative to parent remote directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### upload

          public void upload(java.lang.String remoteDirectory,
                             java.lang.String localFile)
                      throws java.io.IOException

      Uploads a file.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `localFile` - file to upload relative to the current local directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mupload

          public void mupload(java.lang.String remoteDirectory,
                              java.util.Collection<java.lang.String> localFiles)
                       throws java.io.IOException

      Uploads multiple files taken from the current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `localFiles` - sources files
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mupload

          public void mupload(java.lang.String remoteDirectory,
                              java.lang.String... localFiles)
                       throws java.io.IOException

      Uploads multiple files taken from the current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `localFiles` - source files
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mupload

          public void mupload(java.lang.String remoteDirectory,
                              java.util.Enumeration<java.lang.String> localFiles)
                       throws java.io.IOException

      Uploads multiple files taken from the current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `localFiles` - source files
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mupload

          public void mupload(java.lang.String remoteDirectory,
                              java.util.Iterator<java.lang.String> localFiles)
                       throws java.io.IOException

      Uploads multiple files taken from the current local directory.
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `localFiles` - source files
      Throws:
        `java.io.IOException` - if an error occurs

    - #### mupload

          public void mupload(java.lang.String remoteDirectory,
                              java.lang.String regex)
                       throws java.io.IOException

      Uploads multiple files matching the specified regular expression. Uploads are performed relative to current local directory. For example, to upload local files with .txt extension use the regular expression ".*\.txt".
      Parameters:
        `remoteDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `regex` - source file filter
      Throws:
        `java.io.IOException` - if an error occurs

    - #### uploadDir

          public void uploadDir(java.io.File localDirectory,
                                java.lang.String remoteParentDirectory,
                                java.lang.String remoteDirectory)
                         throws java.io.IOException

      Uploads a directory.
      Parameters:
        `localDirectory` - source directory
        `remoteParentDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
        `remoteDirectory` - remote directory name relative to parent remote directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### uploadDir

          public void uploadDir(java.io.File localDirectory,
                                java.lang.String remoteParentDirectory)
                         throws java.io.IOException

      Uploads a directory.
      Parameters:
        `localDirectory` - source directory
        `remoteParentDirectory` - remote directory path with ending path separator (i.e "/user/home/") or empty line for current directory
      Throws:
        `java.io.IOException` - if an error occurs

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved