本文整理汇总了Java中ch.ethz.ssh2.Connection.authenticateWithPassword方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.authenticateWithPassword方法的具体用法?Java Connection.authenticateWithPassword怎么用?Java Connection.authenticateWithPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.ethz.ssh2.Connection
的用法示例。
在下文中一共展示了Connection.authenticateWithPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConn
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
* 获取服务器链接
* @param hostname
* @param username
* @param password
* @return
*/
public static Connection getConn(String hostName,String userName,int sshPort,String passWord){
try {
Connection conn = new Connection(hostName,sshPort);
//连接到主机
conn.connect();
//使用用户名和密码校验
boolean isconn = conn.authenticateWithPassword(userName, passWord);
if(!isconn){
System.out.println("用户名称或者是密码不正确");
}else{
return conn;
}
} catch (IOException e) {
System.out.println("获取服务器链接出现异常:"+e.toString());
return null;
}
return null;
}
示例2: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public Connection getConnection(){
int round = 0;
while(round<maxRoundConnection){
try{
connection = new Connection(server);
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
throw new IOException("Authentication failed...");
}
break;
}catch (Exception e) {
e.printStackTrace();
connection.close();
connection = null;
System.err.println("================= connection is null in round "+round);
try {
Thread.sleep(sshReconnectWatingtime*1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
round++;
}
return connection;
}
示例3: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public Connection getConnection(){
int round = 0;
while(round<maxRoundConnection){
try{
connection = new Connection(server);
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
throw new IOException("Authentication failed...");
}
break;
}catch (Exception e) {
e.printStackTrace();
connection.close();
connection = null;
System.err.println("================= connection is null in round "+round);
try {
Thread.sleep(sshReconnectWatingtime*1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
round++;
}
return connection;
}
示例4: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public Connection getConnection() {
try {
connection = new Connection(server);
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(
username, password);
if (isAuthenticated == false) {
throw new IOException("Authentication failed...");
}
} catch (IOException e) {
e.printStackTrace();
}
return connection;
}
示例5: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public Connection getConnection(){
try{
connection = new Connection(server);
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
throw new IOException("Authentication failed...");
}
}catch (IOException e) {
e.printStackTrace();
}
return connection;
}
示例6: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
private Connection getConnection() {
try {
connection = new Connection(server);
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(
username, password);
if (isAuthenticated == false) {
throw new IOException("Authentication failed...");
}
} catch (IOException e) {
e.printStackTrace();
}
return connection;
}
示例7: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
* 获取连接并校验
* @param ip
* @param port
* @param username
* @param password
* @return Connection
* @throws Exception
*/
private Connection getConnection(String ip, int port,
String username, String password) throws Exception {
Connection conn = new Connection(ip, port);
conn.connect(null, CONNCET_TIMEOUT, CONNCET_TIMEOUT);
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
throw new Exception("SSH authentication failed with [ userName: " +
username + ", password: " + password + "]");
}
return conn;
}
示例8: open
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
* 登陆
* @return boolean
* @throws IOException
*/
public boolean open(){
conn = new Connection(ip);
try {
conn.connect();
return conn.authenticateWithPassword(this.username, this.password);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
示例9: exeRemoteConsole
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public static List<String> exeRemoteConsole(String hostname, String username, String password, String cmd) {
List<String> result = new ArrayList<String>();
//指明连接主机的IP地址
Connection conn = new Connection(hostname);
Session ssh = null;
try {
//连接到主机
conn.connect();
//使用用户名和密码校验
boolean isconn = conn.authenticateWithPassword(username, password);
if (!isconn) {
logger.error("用户名称或者是密码不正确");
} else {
logger.info("已经连接OK");
ssh = conn.openSession();
//使用多个命令用分号隔开
// ssh.execCommand("pwd;cd /tmp;mkdir shb;ls;ps -ef|grep weblogic");
ssh.execCommand(cmd);
//只允许使用一行命令,即ssh对象只能使用一次execCommand这个方法,多次使用则会出现异常
// ssh.execCommand("mkdir hb");
//将屏幕上的文字全部打印出来
InputStream is = new StreamGobbler(ssh.getStdout());
BufferedReader brs = new BufferedReader(new InputStreamReader(is));
for (String line = brs.readLine(); line != null; line = brs.readLine()) {
result.add(line);
}
}
//连接的Session和Connection对象都需要关闭
if (ssh != null) {
ssh.close();
}
conn.close();
} catch (IOException e) {
logger.error("", e);
}
return result;
}
示例10: login
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
* Attempt to login to host
* @param host host name/ip
* @param user user name
* @param pwd user password
* @throws IOException
*/
public void login(String host, String user, String pwd ) throws IOException {
setParams(host, user, pwd, null);
conn = new Connection(host);
info = conn.connect();
if (!conn.authenticateWithPassword(user, pwd)){
throw new IOException("Cant authenticate with user " + user + " and password " + pwd);
}
}
示例11: SSHConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public SSHConnection(String hostname, String username, String password) throws IOException {
/* Create a connection instance */
connection = new Connection(hostname);
/* Now connect */
connection.connect();
/* Authenticate */
boolean isAuthenticated = connection.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
}
示例12: exportDataBase
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
* export database;
*/
public void exportDataBase() {
logger.info("start backup database");
String username = Config.getProperty("jdbc.username_dev");
String password = Config.getProperty("jdbc.password_dev");
String database = Config.getProperty("jdbc.database");
String host = Config.getProperty("jdbc.host_dev");
String os = System.getProperty("os.name");
String file_path = null;
// if (os.toLowerCase().startsWith("win")) { //根据系统类型
// file_path = System.getProperty("user.dir") + "\\sql\\";
// } else {
// file_path = System.getProperty("user.dir") + "/sql/";//保存的路径
// }
file_path = System.getProperty("myblog.path") + "sql";
String file_name = "/myblog" + DateTime.now().toString("yyyyMMddHHmmss") + ".sql";
String file = file_path + file_name;
logger.info("file_path and file_name: " + file);
//server
String s_host = Config.getProperty("server.host");
Integer s_port = Config.getIntProperty("server.port");
String s_username = Config.getProperty("server.username");
String s_password = Config.getProperty("server.password");
try {
StringBuffer sb = new StringBuffer();
sb.append("mysqldump -u " + username + " -p" + password + " -h " + host + " " +
database + " >" + file);
String sql = sb.toString();
logger.info(sql);
//connect to server
Connection connection = new Connection(s_host, s_port);
connection.connect();
boolean isAuth = connection.authenticateWithPassword(s_username, s_password);
if (!isAuth) {
logger.error("server login error");
}
Session session = connection.openSession();
session.execCommand(sql);
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) {
String line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
session.close();
connection.close();
stdout.close();
br.close();
logger.info("backup finish");
logger.info(sb.toString());
} catch (Exception e) {
logger.error("error", e);
}
}
示例13: login
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public boolean login() throws IOException {
conn = new Connection(ipAddr);
conn.connect(); // 连接
return conn.authenticateWithPassword(userName, password); // 认证
}
示例14: getConnection
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
/**
* 获取连接并校验
* @param ip
* @param port
* @param username
* @param password
* @return Connection
* @throws Exception
*/
private Connection getConnection(String ip, int port,
String username, String password) throws Exception {
Connection conn = new Connection(ip, port);
conn.connect(null, CONNCET_TIMEOUT, CONNCET_TIMEOUT);
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
throw new Exception("SSH authentication failed with [ userName: " +
username + ", password: " + password + "]");
}
return conn;
}
示例15: main
import ch.ethz.ssh2.Connection; //导入方法依赖的package包/类
public static void main(String[] args)
{
String hostname = "127.0.0.1";
String username = "joe";
String password = "joespass";
try
{
/* Create a connection instance */
Connection conn = new Connection(hostname);
/* Now connect */
conn.connect();
/* Authenticate.
* If you get an IOException saying something like
* "Authentication method password not supported by the server at this stage."
* then please check the FAQ.
*/
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
/* Create a session */
Session sess = conn.openSession();
sess.execCommand("uname -a && date && uptime && who");
System.out.println("Here is some information about the remote host:");
/*
* This basic example does not handle stderr, which is sometimes dangerous
* (please read the FAQ).
*/
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
/* Show exit status, if available (otherwise "null") */
System.out.println("ExitCode: " + sess.getExitStatus());
/* Close this session */
sess.close();
/* Close the connection */
conn.close();
}
catch (IOException e)
{
e.printStackTrace(System.err);
System.exit(2);
}
}