Class ScpClient

java.lang.Object
com.sshtools.client.scp.ScpClientIO
com.sshtools.client.scp.ScpClient

public class ScpClient extends ScpClientIO
Implements an SCP (Secure Copy) client which may be useful for SSH1 connections and SSH2 where SFTP is not available.
Author:
Lee David Painter
  • Constructor Details

    • ScpClient

      public ScpClient(SshClient ssh) throws com.sshtools.common.permissions.PermissionDeniedException, IOException

      Creates an SCP client. CWD (Current working directory) will be the users home directory.

      Parameters:
      ssh - A connected SshClient
      Throws:
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • ScpClient

      public ScpClient(File cwd, SshClient ssh) throws com.sshtools.common.permissions.PermissionDeniedException, IOException
      Parameters:
      cwd -
      ssh -
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • ScpClient

      public ScpClient(com.sshtools.common.files.AbstractFileFactory<?> fileFactory, SshClient ssh) throws com.sshtools.common.permissions.PermissionDeniedException, IOException

      Creates an SCP client.

      Parameters:
      cwd - The current local directory
      ssh - A connected SshClient
      Throws:
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
  • Method Details

    • setWindowSpace

      public void setWindowSpace(int windowSpace)
    • setPacketSize

      public void setPacketSize(int packetSize)
    • put

      public void put(String localFile, String remoteFile, boolean recursive) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, com.sshtools.common.sftp.SftpStatusException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Uploads a local file onto the remote server.

      Treats localFile as a glob regular expression, and puts the files that match into the remote directory.

      Code examples can be found in ScpConnect.java

      Code Example

       //put all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder relative to the local cwd, and copy them to remoteFile.  If remoteFile is a filename then the remote file will have this name unless multiple local files are matched in which case an exception will be thrown.
       scp.put("docs/unsorted/*rfc*.doc"); 
       

      Parameters:
      localFile - The path to the local file relative to the local current directory; may be a file or directory
      remoteFile - The path on the remote server, may be a file or directory
      recursive - Copy the contents of a directory recursivly
      Throws:
      com.sshtools.common.ssh.SshException - if an IO error occurs during the operation
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
      com.sshtools.common.ssh.ChannelOpenException
    • putFile

      public void putFile(String localFile, String remoteFile, boolean recursive, FileTransferProgress progress, boolean remoteIsDir) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Deprecated.
      Use put method instead.
      Parameters:
      localFile -
      remoteFile -
      recursive -
      progress -
      remoteIsDir - if called by put(string[]...) then remoteFile must be a directory so need -d option.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String localFile, String remoteFile, boolean recursive, FileTransferProgress progress, boolean remoteIsDir) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Parameters:
      localFile -
      remoteFile -
      recursive -
      progress -
      remoteIsDir - if called by put(string[]...) then remoteFile must be a directory so need -d option.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String localFileRegExp, String remoteFile, boolean recursive, FileTransferProgress progress) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, com.sshtools.common.sftp.SftpStatusException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      pattern matches the files in the local directory using "local" as a glob Regular Expression. For the matching file array put is called to copy the file to the remote directory.
      Parameters:
      localFileRegExp -
      remoteFile -
      recursive -
      progress -
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
      com.sshtools.common.sftp.SftpStatusException
    • put

      public void put(String[] localFiles, String remoteFile, boolean recursive) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Uploads an array of local files onto the remote server.

      Parameters:
      localFiles - an array of local files; may be files or directories
      remoteFile - the path on the remote server, may be a file or directory.
      recursive - Copy the contents of directorys recursivly
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException - if an IO error occurs during the operation
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
    • put

      public void put(String[] localFiles, String remoteFile, boolean recursive, FileTransferProgress progress) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Uploads an array of local files onto the remote server.

      Parameters:
      localFiles - an array of local files; may be files or directories
      remoteFile - the path on the remote server, may be a file or directory1
      recursive - Copy the contents of directorys recursivly
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException - if an IO error occurs during the operation
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
    • get

      public void get(String localDir, String[] remoteFiles, boolean recursive) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Downloads an array of remote files to the local computer.

      Parameters:
      localDir - The local path to place the files
      remoteFiles - The path of the remote files
      recursive - recursively copy the contents of a directory
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException - if an IO error occurs during the operation
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
    • get

      public void get(String localFile, String[] remoteFiles, boolean recursive, FileTransferProgress progress) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • get

      public void get(String localFile, String remoteFile, boolean recursive) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Downloads a remote file onto the local computer.

      Parameters:
      localFile - The path to place the file
      remoteFile - The path of the file on the remote server
      recursive - recursivly copy the contents of a directory
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException - if an IO error occurs during the operation
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
    • get

      public void get(String localFile, String remoteFile, boolean recursive, FileTransferProgress progress) throws com.sshtools.common.ssh.SshException, com.sshtools.common.ssh.ChannelOpenException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.ssh.ChannelOpenException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • exit

      public void exit() throws com.sshtools.common.ssh.SshException, IOException
      Throws:
      com.sshtools.common.ssh.SshException
      IOException