本文整理了Java中com.jcraft.jsch.JSch.<init>()
方法的一些代码示例,展示了JSch.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSch.<init>()
方法的具体详情如下:
包路径:com.jcraft.jsch.JSch
类名称:JSch
方法名:<init>
[英]Creates a new JSch object.
[中]创建一个新的JSch对象。
代码示例来源:origin: apache/kylin
private Session newJSchSession() throws JSchException {
JSch jsch = new JSch();
if (identityPath != null) {
jsch.addIdentity(identityPath);
}
Session session = jsch.getSession(username, hostname, port);
if (password != null) {
session.setPassword(password);
}
session.setConfig("StrictHostKeyChecking", "no");
return session;
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] arg) {
try {
JSch jsch = new JSch();
System.out.println("identity added ");
Session session = jsch.getSession(user, host, port);
System.out.println("session created.");
代码示例来源:origin: org.apache.hadoop/hadoop-common
private Session createSession(String host, Args args) throws JSchException {
JSch jsch = new JSch();
for (String keyFile : getKeyFiles()) {
jsch.addIdentity(keyFile);
}
JSch.setLogger(new LogAdapter());
Session session = jsch.getSession(args.user, host, args.sshPort);
session.setConfig("StrictHostKeyChecking", "no");
return session;
}
代码示例来源:origin: stackoverflow.com
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
代码示例来源:origin: alibaba/jstorm
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
代码示例来源:origin: alibaba/jstorm
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
代码示例来源:origin: alibaba/jstorm
String rfile = arg[1].substring(arg[1].indexOf(':') + 1);
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
代码示例来源:origin: alibaba/jstorm
String rfile = arg[1].substring(arg[1].indexOf(':') + 1);
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
代码示例来源:origin: alibaba/jstorm
JSch jsch = new JSch();
Session session = jsch.getSession("fengjian", "localhost", 22);
session.setPassword("");
session.setConfig("StrictHostKeyChecking", "no");
代码示例来源:origin: apache/usergrid
private void setSession() {
JSch ssh;
// wait until SSH port of remote end comes up
boolean success = waitActive( SESSION_CONNECT_TIMEOUT );
if( ! success ) {
LOG.warn( "Port 22 of {} did not open in time", value.getPublicIpAddress() );
}
// try to open ssh session
try {
Thread.sleep( 30000 );
ssh = new JSch();
ssh.addIdentity( value.getSshKeyFile() );
session = ssh.getSession( Utils.DEFAULT_USER, value.getPublicIpAddress() );
session.setConfig( "StrictHostKeyChecking", "no" );
session.connect();
}
catch ( Exception e ) {
LOG.error( "Error while connecting to ssh session of " + value.getPublicIpAddress(), e );
session = null;
}
}
代码示例来源:origin: looly/hutool
/**
* 打开一个新的SSH跳板机会话
*
* @param sshHost 跳板机主机
* @param sshPort 跳板机端口
* @param sshUser 跳板机用户名
* @param sshPass 跳板机密码
* @return SSH会话
*/
public static Session openSession(String sshHost, int sshPort, String sshUser, String sshPass) {
if (StrUtil.isEmpty(sshHost) || sshPort < 0 || StrUtil.isEmpty(sshUser) || StrUtil.isEmpty(sshPass)) {
return null;
}
Session session;
try {
session = new JSch().getSession(sshUser, sshHost, sshPort);
session.setPassword(sshPass);
//设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
} catch (JSchException e) {
throw new JschRuntimeException(e);
}
return session;
}
代码示例来源:origin: stackoverflow.com
JSch jsch = new JSch();
session = jsch.getSession(username, host, 22);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
代码示例来源:origin: looly/hutool
/**
* 打开一个新的SSH跳板机会话
*
* @param sshHost 跳板机主机
* @param sshPort 跳板机端口
* @param sshUser 跳板机用户名
* @param sshPass 跳板机密码
* @return SSH会话
*/
public static Session openSession(String sshHost, int sshPort, String sshUser, String sshPass) {
if (StrUtil.isEmpty(sshHost) || sshPort < 0 || StrUtil.isEmpty(sshUser) || StrUtil.isEmpty(sshPass)) {
return null;
}
Session session;
try {
session = new JSch().getSession(sshUser, sshHost, sshPort);
session.setPassword(sshPass);
//设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
} catch (JSchException e) {
throw new JschRuntimeException(e);
}
return session;
}
代码示例来源:origin: alibaba/jstorm
public void execute(String command) throws Exception {
JSch jsch = new JSch();
Session session = jsch.getSession(username, host, 22);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
代码示例来源:origin: stackoverflow.com
System.out.println("preparing the host information for sftp.");
try {
JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
代码示例来源:origin: org.apache.hadoop/hadoop-common
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession(user, host);
} else {
session = jsch.getSession(user, host, port);
代码示例来源:origin: stackoverflow.com
import com.jcraft.jsch.*;
public class TestJSch {
public static void main(String args[]) {
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession("username", "127.0.0.1", 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("password");
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.get("remotefile.txt", "localfile.txt");
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: stackoverflow.com
Session session = null;
Channel channel = null;
try {
JSch ssh = new JSch();
ssh.setKnownHosts("/path/of/known_hosts/file");
session = ssh.getSession("username", "host", 22);
session.setPassword("password");
session.connect();
channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftp = (ChannelSftp) channel;
sftp.put("/path/of/local/file", "/path/of/ftp/file");
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
} finally {
if (channel != null) {
channel.disconnect();
}
if (session != null) {
session.disconnect();
}
}
代码示例来源:origin: stackoverflow.com
JSch jsch = new JSch();
Session session = jsch.getSession( "remote-username", "remote-host" );
代码示例来源:origin: apache/incubator-gobblin
JSch jsch = new JSch();
this.session = jsch.getSession(userName, hostName, port);
this.session.setConfig("PreferredAuthentications", "publickey,password");
内容来源于网络,如有侵权,请联系作者删除!