|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.enterprisedt.net.ftp.ssh.SCPClient
public class SCPClient
SCPClient implements SCP (SSH secure copy).
Connections are established when the connect() is invoked.
Before it is called, the remote host must be defined, and
host verification and client authentication should be
configured.
Host Validation is the process of verifying that a host that is
being connected to is the host that was requested. Host validation is
done through an instance of SSHFTPValidator or a subclass
thereof. By default, SCPClient, has an instance of
this class that is available by means of the getValidator()
method. Unless specialized validation functionality is required,
initialization of validation functionality may be done simply by invoking
methods on this object.
There are four approaches to setting up host validation:
ftpClient.getValidator().setHostValidationEnabled(false);
jackspc ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIE...If there are more than one host using a given key the host-name may be replaced by a comma-separated list of host-names. Wildcards may not be used. A host-file is loaded as follows:
ftpClient.getValidator().loadKnownHosts("~/.ssh/known_hosts");
ftpClient.getValidator().addKnownHost("host1pk.pub");
ftpClient.getValidator().addKnownHost("host2pk.pub");
Public keys should be in OpenSSH or SECSH format.
Client Authentication is the method used by the server to authenticate
clients. Different servers will enforce different policies for authenticating
clients. SCPClient currently offers two authentication methods:
setAuthentication as follows:
ftpClient.setAuthentication("jack", "my_ftp_password");
ftpClient.setAuthentication("myprivatekey", "jack", "my_keyfile_password");
The user-name is the name of the user on the SFTP server, but the passphrase
is the password for the key-file (if there is a password).
| Field Summary | |
|---|---|
protected com.enterprisedt.net.j2ssh.authentication.SshAuthenticationClient |
authenticator
J2SSH authenticator. |
protected com.enterprisedt.net.j2ssh.configuration.SshConnectionProperties |
connProps
J2SSH SshConnectionProperties instance. |
static int |
DEFAULT_PORT
Default SSH port. |
protected int |
deleteCount
Count of deleted files |
protected int |
downloadCount
Count of downloaded files |
protected com.enterprisedt.util.license.EDTProduct |
expectedProduct
The expected product contained in our license |
protected java.lang.String |
id
Id of instance |
protected com.enterprisedt.util.license.LicensePropertiesBase |
license
The license details |
protected com.enterprisedt.net.j2ssh.authentication.SshAuthenticationClient |
retryAuthenticator
J2SSH authenticator. |
protected com.enterprisedt.net.j2ssh.SshClient |
ssh
J2SSH SshClient instance. |
protected int |
uploadCount
Count of uploaded files |
protected SSHFTPValidator |
validator
Encapsulation and extension of J2SSH AbstractKnownHostsKeyVerification. |
| Constructor Summary | |
|---|---|
SCPClient()
Constructs an SCP client. |
|
| Method Summary | |
|---|---|
protected void |
checkConnection(boolean shouldBeConnected)
Checks if the client has connected to the server and throws an exception if it hasn't. |
void |
connect()
Connects to the server at the address and port number defined in the constructor. |
boolean |
connected()
Is the client currently connected? |
protected void |
connectSSH()
Connects to the server at the address and port number defined in the constructor. |
void |
disableAllAlgorithms()
Disables all algorithms. |
void |
disableAllAlgorithms(int algorithmType)
Disables all algorithms of a particular type. |
java.lang.String |
executeCommand(java.lang.String command)
Execute a command on the remote server. |
void |
get(java.lang.String localPath,
java.lang.String remoteFile)
Download a file |
int |
getDeleteCount()
Get the number of files deleted since the count was reset |
int |
getDownloadCount()
Get the number of files downloaded since the count was reset |
SSHFTPAlgorithm[] |
getEnabledAlgorithms()
Returns an array containing all enabled algorithms (of all types). |
SSHFTPAlgorithm[] |
getEnabledAlgorithms(int algorithmType)
Returns an array containing all enabled algorithms of a particular type. |
SSHFTPPublicKey |
getHostPublicKey()
Provides access to the current server's public key. |
static SSHFTPPublicKey |
getHostPublicKey(java.lang.String remoteHost)
Helper method that may be used to obtain a server's public key without instantiating an SCPClient. |
static SSHFTPPublicKey |
getHostPublicKey(java.lang.String remoteHost,
int remotePort)
Helper method that may be used to obtain a server's public key without instantiating an SCPClient. |
java.lang.String |
getId()
Get the identifying string for this instance |
java.lang.String |
getRemoteHost()
|
int |
getRemotePort()
Returns the SSH port of the remote host. |
int |
getTimeout()
|
int |
getTransportProvider()
Get the currently set transport provider |
int |
getUploadCount()
Get the number of files uploaded since the count was reset |
SSHFTPValidator |
getValidator()
Returns a reference to the current host validator. |
boolean |
isAlgorithmEnabled(SSHFTPAlgorithm algorithm)
Returns true if the given algorithm is enabled. |
java.lang.String |
put(java.lang.String localPath,
java.lang.String remoteFile)
Upload a file. |
void |
quit()
|
void |
quitImmediately()
|
void |
resetDeleteCount()
Reset the count of deleted files to zero. |
void |
resetDownloadCount()
Reset the count of downloaded files to zero. |
void |
resetUploadCount()
Reset the count of uploaded files to zero. |
void |
setAlgorithmEnabled(SSHFTPAlgorithm algorithm,
boolean enable)
Enable/disable the given algorithm. |
void |
setAuthentication(java.io.InputStream inStr,
java.lang.String userName,
java.lang.String keyFilePassphrase)
Set up the SFTP client to authenticate using a private/public key-pair. |
void |
setAuthentication(java.lang.String user,
SSHAuthPrompt[] prompts)
Set up keyboard-interactive (KBI) authentication by supplying an array of responses to possible prompts by the SSH server |
void |
setAuthentication(java.lang.String userName,
java.lang.String password)
Set up user-name/password authentication. |
void |
setAuthentication(java.lang.String keyFileName,
java.lang.String userName,
java.lang.String keyFilePassphrase)
Set up the SFTP client to authenticate using a private/public key-pair. |
void |
setAuthentication(java.lang.String keyFileName,
java.lang.String userName,
java.lang.String keyFilePassphrase,
java.lang.String userPassword)
Set up the SFTP client to authenticate using a private/public key-pair, followed by password authentication. |
void |
setId(java.lang.String id)
Set the identifying string for this instance |
void |
setProxyParams(ProxyParameters params)
Setup the parameters required for using a proxy |
void |
setRemoteHost(java.lang.String remoteHost)
|
void |
setRemotePort(int port)
Set the SSH port of the remote host. |
void |
setTimeout(int millis)
|
void |
setTransportProvider(int provider)
Set the type of transport provider to use. |
void |
setValidator(SSHFTPValidator validator)
Sets the host validator. |
java.lang.String |
system()
Get a string representing the remote system. |
java.lang.String |
toString()
String representation |
protected void |
validateAlgorithms()
Check to see if at least one of each type of algorithm is enabled. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_PORT
protected com.enterprisedt.net.j2ssh.SshClient ssh
protected com.enterprisedt.net.j2ssh.configuration.SshConnectionProperties connProps
protected SSHFTPValidator validator
AbstractKnownHostsKeyVerification.
protected com.enterprisedt.net.j2ssh.authentication.SshAuthenticationClient authenticator
protected com.enterprisedt.net.j2ssh.authentication.SshAuthenticationClient retryAuthenticator
protected java.lang.String id
protected int downloadCount
protected int uploadCount
protected int deleteCount
protected final com.enterprisedt.util.license.EDTProduct expectedProduct
protected com.enterprisedt.util.license.LicensePropertiesBase license
| Constructor Detail |
|---|
public SCPClient()
| Method Detail |
|---|
public java.lang.String getId()
public void setId(java.lang.String id)
id - identifying string
public java.lang.String system()
throws FTPException,
java.io.IOException
FTPException
java.io.IOExceptionpublic int getDownloadCount()
public void resetDownloadCount()
public int getUploadCount()
public void resetUploadCount()
public int getDeleteCount()
public void resetDeleteCount()
public SSHFTPValidator getValidator()
SSHFTPValidator. If
customized host validation is required
then setValidator() should be used to set up
the client to use a subclass
of SCPClient.
public void setValidator(SSHFTPValidator validator)
throws FTPException
SCPClient. If customized host validation is required
then this method should be used to set up the client to use a subclass
of SCPClient.
validator - The host validator to set.
FTPException
public static SSHFTPPublicKey getHostPublicKey(java.lang.String remoteHost)
throws FTPException
SCPClient. This method returns an
SSHFTPPublicKey object whose SSHFTPPublicKey.write(OutputStream, int)
method may be used to write the public key to a file. The method will
return null if a public key could not be retrieved. Logging may
be used to discover any connection problems. If more advanced settings are
required then an instance of SCPClient should be used.
remoteHost - Address of the server whose public key is to be fetched.
SSHFTPPublicKey representing
FTPException
public static SSHFTPPublicKey getHostPublicKey(java.lang.String remoteHost,
int remotePort)
throws FTPException
SCPClient. This method returns an
SSHFTPPublicKey object SSHFTPPublicKey.write(OutputStream,int)
method may be used to write the public key to a file. The method will
return null if a public key could not be retrieved. Logging may
be used to discover any connection problems. If more advanced settings are
required then an instance of SCPClient should be used.
remoteHost - Address of the server whose public key is to be fetched.remotePort - Port of the server whose public key is to be fetched.
SSHFTPPublicKey representing
FTPExceptionpublic SSHFTPPublicKey getHostPublicKey()
null before the first connection attempt is made.
This method is particularly useful if the server's public key is not
available by other means. In such cases a connection attempt should be made
without adding any known hosts. This attempt will fail, but getHostPublicKey()
may be used afterwards to obtain the public key. The
SSHFTPPublicKey.write(OutputStream,int) method may be used to write it
to a file for use in subsequent connections.
Note that null may be returned after a connection attempt is made if the attempt failed before public keys were exchanged between the client and the server.
public void setAuthentication(java.lang.String userName,
java.lang.String password)
throws FTPException
connect method is invoked). This method first attempts to
use password authentication, and if that fails, falls back to keyboard-interactive
authentication via password
userName - User-name as set up on the SFTP server.password - Password as set up on the SFTP server.
FTPException - Thrown if an SFTP-related error occurs.
public void setAuthentication(java.lang.String user,
SSHAuthPrompt[] prompts)
throws FTPException
user - user to login asprompts - prompt responses supplied to pass the server authentication prompts
FTPException
public void setAuthentication(java.lang.String keyFileName,
java.lang.String userName,
java.lang.String keyFilePassphrase)
throws java.io.IOException,
FTPException
connect method is invoked).
The key-file can be in either OpenSSH format (generated by default by ssh-keygen) or SECSH format.
The file may or may not be password protected depending on how it was generated.
keyFileName - File containing the private key.userName - User-name as set up on the server.keyFilePassphrase - (Optional) Key-file passphrase.
java.io.IOException - Thrown if the key-file could not be read.
SSHFTPException - Thrown if an SFTP-related error occurred.
FTPException
public void setAuthentication(java.io.InputStream inStr,
java.lang.String userName,
java.lang.String keyFilePassphrase)
throws java.io.IOException,
FTPException
connect method is invoked).
The key-file can be in either OpenSSH format (generated by default by ssh-keygen) or SECSH format.
The file may or may not be password protected depending on how it was generated.
inStr - InputStream containing the private key.userName - User-name as set up on the server.keyFilePassphrase - (Optional) Key-file passphrase.
java.io.IOException - Thrown if the key-file could not be read.
SSHFTPException - Thrown if an SFTP-related error occurred.
FTPException
public void setAuthentication(java.lang.String keyFileName,
java.lang.String userName,
java.lang.String keyFilePassphrase,
java.lang.String userPassword)
throws java.io.IOException,
FTPException
connect method is invoked).
The key-file can be in either OpenSSH format (generated by default by ssh-keygen) or SECSH format.
The file may or may not be password protected depending on how it was generated.
keyFileName - File containing the private key.userName - User-name as set up on the server.keyFilePassphrase - (Optional) Key-file passphrase.userPassword - User's password
java.io.IOException - Thrown if the key-file could not be read.
SSHFTPException - Thrown if an SFTP-related error occurred.
FTPException
protected void validateAlgorithms()
throws SSHFTPException
SSHFTPException - Thrown if one algorithm-type has no enabled algorithms.public SSHFTPAlgorithm[] getEnabledAlgorithms()
public SSHFTPAlgorithm[] getEnabledAlgorithms(int algorithmType)
throws SSHFTPException
algorithmType - Type of algorithms to return (See SSHFTPAlgorithm).
SSHFTPException - Thrown if the given algorithm-type is invalid.
public void disableAllAlgorithms(int algorithmType)
throws SSHFTPException
algorithmType - Type of algorithms to return (See SSHFTPAlgorithm).
SSHFTPExceptionpublic void disableAllAlgorithms()
public void setAlgorithmEnabled(SSHFTPAlgorithm algorithm,
boolean enable)
algorithm - Algorithm to enable/disable.enable - Flag indicating whether the algorithm should be enabled or disabled.public boolean isAlgorithmEnabled(SSHFTPAlgorithm algorithm)
true if the given algorithm is enabled.
algorithm - Algorithm to return status of.public java.lang.String getRemoteHost()
public void setRemoteHost(java.lang.String remoteHost)
throws FTPException
FTPExceptionpublic int getRemotePort()
public void setRemotePort(int port)
throws FTPException
port - The port to set.
FTPException - Thrown if the client is already connected to the server.public void setProxyParams(ProxyParameters params)
params - parameter objectpublic void setTransportProvider(int provider)
provider - provider integerpublic int getTransportProvider()
public int getTimeout()
public void setTimeout(int millis)
throws FTPException
FTPException
public void connect()
throws java.io.IOException,
FTPException
java.io.IOException - Thrown if there is a TCP/IP-related error.
FTPException - Thrown if client is already connected or if there is
a configuration error, or if a connection could not be established.
protected void connectSSH()
throws java.io.IOException,
FTPException
java.io.IOException - Thrown if there is a TCP/IP-related error.
FTPException - Thrown if client is already connected or if there is
a configuration error, or if a connection could not be established.
public java.lang.String executeCommand(java.lang.String command)
throws FTPException,
java.io.IOException
command - command to execute
FTPException
java.io.IOException
protected void checkConnection(boolean shouldBeConnected)
throws FTPException
FTPException - Thrown if the client has not connected to the server.public boolean connected()
public java.lang.String put(java.lang.String localPath,
java.lang.String remoteFile)
throws java.io.IOException,
FTPException
localPath - path of local file to be uploadedremoteFile - path of remote file to upload to
java.io.IOException
FTPException
public void get(java.lang.String localPath,
java.lang.String remoteFile)
throws java.io.IOException,
FTPException
localPath - path of local file to download toremoteFile - path of remote file
java.io.IOException
FTPException
public void quit()
throws java.io.IOException,
FTPException
java.io.IOException
FTPException
public void quitImmediately()
throws java.io.IOException,
FTPException
java.io.IOException
FTPExceptionpublic java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||