verinec.util
Class SshCopy

java.lang.Object
  extended by verinec.util.SshCopy

public class SshCopy
extends Object

Do remote file copying using secure shell (Scp). Currently depends on J2ssh, which is not very reliable. When the files to copy contain characters illegal on target system, J2ssh just ignores them without any warning.

Author:
david.buchmann at unifr.ch
See Also:
J2sshProcess

Field Summary
private  com.sshtools.j2ssh.ScpClient client
           
private  com.sshtools.j2ssh.SshClient ssh
           
 
Constructor Summary
SshCopy(String host, int port, String username, String password, String prefPublicKey, File keyfile, String passphrase, String hostVerification)
          Create a scp client with a remote system to copy files.
 
Method Summary
 void disconnect()
          Close the connection to the remote system.
 void get(String local, String remote, boolean recursive)
          Copy a file from a remote system to our system.
static void get(String local, String remote, boolean recursive, String host, int port, String username, String password, String prefPublicKey, File keyfile, String passphrase, String hostVerification)
          Copy files from the remote system to our system.
 void put(String local, String remote, boolean recursive)
          Copy a file from our system to the remote system.
static void put(String local, String remote, boolean recursive, String host, int port, String username, String password, String prefPublicKey, File keyfile, String passphrase, String hostVerification)
          Copy a file from our system to the remote system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

client

private com.sshtools.j2ssh.ScpClient client

ssh

private com.sshtools.j2ssh.SshClient ssh
Constructor Detail

SshCopy

public SshCopy(String host,
               int port,
               String username,
               String password,
               String prefPublicKey,
               File keyfile,
               String passphrase,
               String hostVerification)
        throws VerinecException
Create a scp client with a remote system to copy files. You should call disconnect() when you do no longer need the connection.

Parameters:
host - Hostname to connect to
port - A port number to use, pass -1 to leave default
username - The username to log into the remote system.
password - The password to use for password authentication. If null, no password auth is attempted.
prefPublicKey - The preferred public key algorithm. 'ssh-rsa' is a good choice.
keyfile - The path to file containing the private keys. If null, no public key auth is attempted.
passphrase - The passphrase to use with the key file. Pass null if no pass phrase needed.
hostVerification - Requirement for host verification. Possible values are ignore, interactive or the expected host fingerprint.
Throws:
VerinecException - If the connection can not be opened for some reason.
Method Detail

disconnect

public void disconnect()
Close the connection to the remote system.


put

public void put(String local,
                String remote,
                boolean recursive)
         throws IOException
Copy a file from our system to the remote system.

Parameters:
local - The source file path on local machine.
remote - The target file path on remote machine.
recursive - Whether directories should be copyied recursively.
Throws:
IOException - If the copy fails.

get

public void get(String local,
                String remote,
                boolean recursive)
         throws IOException
Copy a file from a remote system to our system.

Parameters:
local - The target local file path.
remote - The source file path on remote machine.
recursive - Whether directories should be copyied recursively.
Throws:
IOException - If the copy fails.

put

public static void put(String local,
                       String remote,
                       boolean recursive,
                       String host,
                       int port,
                       String username,
                       String password,
                       String prefPublicKey,
                       File keyfile,
                       String passphrase,
                       String hostVerification)
                throws VerinecException,
                       IOException
Copy a file from our system to the remote system. Establishes a connection and closes it down after the copy.

Parameters:
local - The source file path on local machine.
remote - The target file path on remote machine.
recursive - Whether directories should be copyied recursively.
host - Hostname to connect to
port - A port number to use, pass -1 to leave default
username - The username to log into the remote system.
password - The password to use for password authentication. If null, no password auth is attempted.
prefPublicKey - The preferred public key algorithm. 'ssh-rsa' is a good choice.
keyfile - The path to file containing the private keys. If null, no public key auth is attempted.
passphrase - The passphrase to use with the key file. Pass null if no pass phrase needed.
hostVerification - Requirement for host verification. Possible values are ignore, interactive or the expected host fingerprint.
Throws:
VerinecException - If connecting to the remot system fails.
IOException - If the copy fails.

get

public static void get(String local,
                       String remote,
                       boolean recursive,
                       String host,
                       int port,
                       String username,
                       String password,
                       String prefPublicKey,
                       File keyfile,
                       String passphrase,
                       String hostVerification)
                throws VerinecException,
                       IOException
Copy files from the remote system to our system. Establishes a connection and closes it down after the copy.

Parameters:
local - The target local file path.
remote - The source file path on remote machine.
recursive - Whether directories should be copyied recursively.
host - Hostname to connect to
port - A port number to use, pass -1 to leave default
username - The username to log into the remote system.
password - The password to use for password authentication. If null, no password auth is attempted.
prefPublicKey - The preferred public key algorithm. 'ssh-rsa' is a good choice.
keyfile - The path to file containing the private keys. If null, no public key auth is attempted.
passphrase - The passphrase to use with the key file. Pass null if no pass phrase needed.
hostVerification - Requirement for host verification. Possible values are ignore, interactive or the expected host fingerprint.
Throws:
VerinecException - If connecting to the remot system fails.
IOException - If the copy fails.

Copyright © 2005 Verinec, DIUF