com.sshtools.scp
Class ScpClient

java.lang.Object
  extended bycom.maverick.scp.ScpClientIO
      extended bycom.sshtools.scp.ScpClient
All Implemented Interfaces:
Client

public class ScpClient
extends ScpClientIO
implements Client

Implements an SCP (Secure Copy) client which may be useful for SSH1 connections and SSH2 where SFTP is not available.

Author:
Lee David Painter

Nested Class Summary
protected  class ScpClient.ScpEngine
           Implements an SCP Engine by extending J2SSH Mavericjs ScpEngineIO
 
Nested classes inherited from class com.maverick.scp.ScpClientIO
ScpClientIO.ScpEngineIO
 
Field Summary
 
Fields inherited from class com.maverick.scp.ScpClientIO
ssh
 
Constructor Summary
ScpClient(java.io.File cwd, SshClient ssh)
           Creates an SCP client.
ScpClient(SshClient ssh)
           Creates an SCP client.
 
Method Summary
 void exit()
           
 void get(java.lang.String localDir, java.lang.String[] remoteFiles, boolean recursive)
           Downloads an array of remote files to the local computer.
 void get(java.lang.String localFile, java.lang.String[] remoteFiles, boolean recursive, FileTransferProgress progress)
           
 void get(java.lang.String localFile, java.lang.String remoteFile, boolean recursive)
           Downloads a remote file onto the local computer.
 void get(java.lang.String localFile, java.lang.String remoteFile, boolean recursive, FileTransferProgress progress)
           
 void put(java.lang.String[] localFiles, java.lang.String remoteFile, boolean recursive)
           Uploads an array of local files onto the remote server.
 void put(java.lang.String[] localFiles, java.lang.String remoteFile, boolean recursive, FileTransferProgress progress)
           Uploads an array of local files onto the remote server.
 void put(java.lang.String localFile, java.lang.String remoteFile, boolean recursive)
           Uploads a local file onto the remote server.
 void put(java.lang.String localFileRegExp, java.lang.String remoteFile, boolean recursive, FileTransferProgress progress)
          pattern matches the files in the local directory using "local" as a glob Regular Expression.
 void putFile(java.lang.String localFile, java.lang.String remoteFile, boolean recursive, FileTransferProgress progress, boolean remoteIsDir)
           
 
Methods inherited from class com.maverick.scp.ScpClientIO
get, get, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScpClient

public ScpClient(SshClient ssh)

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

Parameters:
ssh - A connected SshClient

ScpClient

public ScpClient(java.io.File cwd,
                 SshClient ssh)

Creates an SCP client.

Parameters:
cwd - The current local directory
ssh - A connected SshClient
Method Detail

put

public void put(java.lang.String localFile,
                java.lang.String remoteFile,
                boolean recursive)
         throws SshException,
                ChannelOpenException,
                SftpStatusException

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:
SshException - if an IO error occurs during the operation
SftpStatusException
ChannelOpenException

putFile

public void putFile(java.lang.String localFile,
                    java.lang.String remoteFile,
                    boolean recursive,
                    FileTransferProgress progress,
                    boolean remoteIsDir)
             throws SshException,
                    ChannelOpenException
Parameters:
localFile -
remoteFile -
recursive -
progress -
remoteIsDir - if called by put(string[]...) then remoteFile must be a directory so need -d option.
Throws:
SshException
ChannelOpenException

put

public void put(java.lang.String localFileRegExp,
                java.lang.String remoteFile,
                boolean recursive,
                FileTransferProgress progress)
         throws SshException,
                ChannelOpenException
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:
SshException
ChannelOpenException

put

public void put(java.lang.String[] localFiles,
                java.lang.String remoteFile,
                boolean recursive)
         throws SshException,
                ChannelOpenException

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:
java.io.IOException - if an IO error occurs during the operation
SshException
ChannelOpenException

put

public void put(java.lang.String[] localFiles,
                java.lang.String remoteFile,
                boolean recursive,
                FileTransferProgress progress)
         throws SshException,
                ChannelOpenException

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:
java.io.IOException - if an IO error occurs during the operation
SshException
ChannelOpenException

get

public void get(java.lang.String localDir,
                java.lang.String[] remoteFiles,
                boolean recursive)
         throws SshException,
                ChannelOpenException

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:
java.io.IOException - if an IO error occurs during the operation
SshException
ChannelOpenException

get

public void get(java.lang.String localFile,
                java.lang.String[] remoteFiles,
                boolean recursive,
                FileTransferProgress progress)
         throws SshException,
                ChannelOpenException
Throws:
SshException
ChannelOpenException

get

public void get(java.lang.String localFile,
                java.lang.String remoteFile,
                boolean recursive)
         throws SshException,
                ChannelOpenException

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:
java.io.IOException - if an IO error occurs during the operation
SshException
ChannelOpenException

get

public void get(java.lang.String localFile,
                java.lang.String remoteFile,
                boolean recursive,
                FileTransferProgress progress)
         throws SshException,
                ChannelOpenException
Throws:
SshException
ChannelOpenException

exit

public void exit()
          throws SshException,
                 ShellTimeoutException,
                 java.io.IOException
Specified by:
exit in interface Client
Throws:
SshException
ShellTimeoutException
java.io.IOException


Copyright © 2003 3SP LTD. All Rights Reserved.