Package com.jcraft.jsch
Class JSch
- java.lang.Object
-
- com.jcraft.jsch.JSch
-
public class JSch extends Object
-
-
Constructor Summary
Constructors Constructor Description JSch()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addIdentity(Identity identity, byte[] passphrase)
Sets the private key, which will be referred in the public key authentication.void
addIdentity(String prvkey)
Sets the private key, which will be referred in the public key authentication.void
addIdentity(String prvkey, byte[] passphrase)
Sets the private key, which will be referred in the public key authentication.void
addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase)
Sets the private key, which will be referred in the public key authentication.void
addIdentity(String prvkey, String passphrase)
Sets the private key, which will be referred in the public key authentication.void
addIdentity(String prvkey, String pubkey, byte[] passphrase)
Sets the private key, which will be referred in the public key authentication.protected void
addSession(Session session)
static String
getConfig(String key)
Returns the config value for the specified key.ConfigRepository
getConfigRepository()
HostKeyRepository
getHostKeyRepository()
Returns the current hostkey repository.Vector
getIdentityNames()
Lists names of identities included in the identityRepository.IdentityRepository
getIdentityRepository()
Session
getSession(String host)
Instantiates theSession
object withhost
.Session
getSession(String username, String host)
Instantiates theSession
object withusername
andhost
.Session
getSession(String username, String host, int port)
Instantiates theSession
object with givenusername
,host
andport
.void
removeAllIdentity()
Removes all identities from identityRepository.void
removeIdentity(Identity identity)
Removes the identity from identityRepository.void
removeIdentity(String name)
Deprecated.use #removeIdentity(Identity identity)protected boolean
removeSession(Session session)
static void
setConfig(String key, String value)
Sets or Overrides the configuration.static void
setConfig(Hashtable newconf)
Sets or Overrides the configuration.void
setConfigRepository(ConfigRepository configRepository)
void
setHostKeyRepository(HostKeyRepository hkrepo)
Sets the hostkey repository.void
setIdentityRepository(IdentityRepository identityRepository)
Sets theidentityRepository
, which will be referred in the public key authentication.void
setKnownHosts(InputStream stream)
Sets the instance ofKnownHosts
generated withstream
.void
setKnownHosts(String filename)
Sets the instance ofKnownHosts
, which refers tofilename
.static void
setLogger(Logger logger)
Sets the logger
-
-
-
Field Detail
-
VERSION
public static final String VERSION
The version number.- See Also:
- Constant Field Values
-
-
Method Detail
-
setIdentityRepository
public void setIdentityRepository(IdentityRepository identityRepository)
Sets theidentityRepository
, which will be referred in the public key authentication.- Parameters:
identityRepository
- ifnull
is given, the default repository, which usually refers to ~/.ssh/, will be used.- See Also:
getIdentityRepository()
-
getIdentityRepository
public IdentityRepository getIdentityRepository()
-
getConfigRepository
public ConfigRepository getConfigRepository()
-
setConfigRepository
public void setConfigRepository(ConfigRepository configRepository)
-
getSession
public Session getSession(String host) throws JSchException
Instantiates theSession
object withhost
. The user name and port number will be retrieved from ConfigRepository. If user name is not given, the system property "user.name" will be referred.- Parameters:
host
- hostname- Returns:
- the instance of
Session
class. - Throws:
JSchException
- ifusername
orhost
are invalid.- See Also:
getSession(String username, String host, int port)
,Session
,ConfigRepository
-
getSession
public Session getSession(String username, String host) throws JSchException
Instantiates theSession
object withusername
andhost
. The TCP port 22 will be used in making the connection. Note that the TCP connection must not be established until Session#connect().- Parameters:
username
- user namehost
- hostname- Returns:
- the instance of
Session
class. - Throws:
JSchException
- ifusername
orhost
are invalid.- See Also:
getSession(String username, String host, int port)
,Session
-
getSession
public Session getSession(String username, String host, int port) throws JSchException
Instantiates theSession
object with givenusername
,host
andport
. Note that the TCP connection must not be established until Session#connect().- Parameters:
username
- user namehost
- hostnameport
- port number- Returns:
- the instance of
Session
class. - Throws:
JSchException
- ifusername
orhost
are invalid.- See Also:
getSession(String username, String host, int port)
,Session
-
addSession
protected void addSession(Session session)
-
removeSession
protected boolean removeSession(Session session)
-
setHostKeyRepository
public void setHostKeyRepository(HostKeyRepository hkrepo)
Sets the hostkey repository.- Parameters:
hkrepo
-- See Also:
HostKeyRepository
,KnownHosts
-
setKnownHosts
public void setKnownHosts(String filename) throws JSchException
Sets the instance ofKnownHosts
, which refers tofilename
.- Parameters:
filename
- filename of known_hosts file.- Throws:
JSchException
- if the given filename is invalid.- See Also:
KnownHosts
-
setKnownHosts
public void setKnownHosts(InputStream stream) throws JSchException
Sets the instance ofKnownHosts
generated withstream
.- Parameters:
stream
- the instance of InputStream from known_hosts file.- Throws:
JSchException
- if an I/O error occurs.- See Also:
KnownHosts
-
getHostKeyRepository
public HostKeyRepository getHostKeyRepository()
Returns the current hostkey repository. By the default, this method will the instance ofKnownHosts
.- Returns:
- current hostkey repository.
- See Also:
HostKeyRepository
,KnownHosts
-
addIdentity
public void addIdentity(String prvkey) throws JSchException
Sets the private key, which will be referred in the public key authentication.- Parameters:
prvkey
- filename of the private key.- Throws:
JSchException
- ifprvkey
is invalid.- See Also:
addIdentity(String prvkey, String passphrase)
-
addIdentity
public void addIdentity(String prvkey, String passphrase) throws JSchException
Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered withpassphrase
.- Parameters:
prvkey
- filename of the private key.passphrase
- passphrase forprvkey
.- Throws:
JSchException
- ifpassphrase
is not right.- See Also:
addIdentity(String prvkey, byte[] passphrase)
-
addIdentity
public void addIdentity(String prvkey, byte[] passphrase) throws JSchException
Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered withpassphrase
.- Parameters:
prvkey
- filename of the private key.passphrase
- passphrase forprvkey
.- Throws:
JSchException
- ifpassphrase
is not right.- See Also:
addIdentity(String prvkey, String pubkey, byte[] passphrase)
-
addIdentity
public void addIdentity(String prvkey, String pubkey, byte[] passphrase) throws JSchException
Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered withpassphrase
.- Parameters:
prvkey
- filename of the private key.pubkey
- filename of the public key.passphrase
- passphrase forprvkey
.- Throws:
JSchException
- ifpassphrase
is not right.
-
addIdentity
public void addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase) throws JSchException
Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered withpassphrase
.- Parameters:
name
- name of the identity to be used to retrieve it in the identityRepository.prvkey
- private key in byte array.pubkey
- public key in byte array.passphrase
- passphrase forprvkey
.- Throws:
JSchException
-
addIdentity
public void addIdentity(Identity identity, byte[] passphrase) throws JSchException
Sets the private key, which will be referred in the public key authentication. Before registering it into identityRepository, it will be deciphered withpassphrase
.- Parameters:
identity
- private key.passphrase
- passphrase foridentity
.- Throws:
JSchException
- ifpassphrase
is not right.
-
removeIdentity
public void removeIdentity(String name) throws JSchException
Deprecated.use #removeIdentity(Identity identity)- Throws:
JSchException
-
removeIdentity
public void removeIdentity(Identity identity) throws JSchException
Removes the identity from identityRepository.- Parameters:
identity
- the indentity to be removed.- Throws:
JSchException
- ifidentity
is invalid.
-
getIdentityNames
public Vector getIdentityNames() throws JSchException
Lists names of identities included in the identityRepository.- Returns:
- names of identities
- Throws:
JSchException
- if identityReposory has problems.
-
removeAllIdentity
public void removeAllIdentity() throws JSchException
Removes all identities from identityRepository.- Throws:
JSchException
- if identityReposory has problems.
-
getConfig
public static String getConfig(String key)
Returns the config value for the specified key.- Parameters:
key
- key for the configuration.- Returns:
- config value
-
setConfig
public static void setConfig(Hashtable newconf)
Sets or Overrides the configuration.- Parameters:
newconf
- configurations
-
setConfig
public static void setConfig(String key, String value)
Sets or Overrides the configuration.- Parameters:
key
- key for the configurationvalue
- value for the configuration
-
-