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; }
public void login( String password ) throws KettleJobException { this.password = password; s.setPassword( this.getPassword() ); try { java.util.Properties config = new java.util.Properties(); config.put( "StrictHostKeyChecking", "no" ); // set compression property // zlib, none String compress = getCompression(); if ( compress != null ) { config.put( COMPRESSION_S2C, compress ); config.put( COMPRESSION_C2S, compress ); } s.setConfig( config ); s.connect(); Channel channel = s.openChannel( "sftp" ); channel.connect(); c = (ChannelSftp) channel; } catch ( JSchException e ) { throw new KettleJobException( e ); } }
session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); System.out.println("Establishing Connection...");
/** * 打开一个新的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; }
/** * 打开一个新的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; }
Session session = jsch.getSession(user, host, 22); session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); session.connect();
session.setPassword("123fj"); session.setConfig("StrictHostKeyChecking", "no"); session.connect();
public static Session createSession(final SFTPConfiguration conf, final JSch jsch) throws JSchException, IOException { if (conf == null || null == jsch) { throw new NullPointerException(); } final Hashtable<String, String> newOptions = new Hashtable<>(); Session session = jsch.getSession(conf.username, conf.hostname, conf.port); final String hostKeyVal = conf.hostkeyFile; if (null != hostKeyVal) { try { jsch.setKnownHosts(hostKeyVal); } catch (final IndexOutOfBoundsException iob) { throw new IOException("Unable to establish connection due to bad known hosts key file " + hostKeyVal, iob); } } else { newOptions.put("StrictHostKeyChecking", "no"); session.setConfig(newOptions); } final String privateKeyVal = conf.privatekeyFile; if (null != privateKeyVal) { jsch.addIdentity(privateKeyVal, conf.privateKeypassphrase); } if (null != conf.password) { session.setPassword(conf.password); } session.setTimeout(conf.connectionTimeout); //set timeout for connection session.connect(); session.setTimeout(conf.dataTimeout); //set timeout for data transfer return session; }
Session session = jsch.getSession(user, host, 22); session.setPassword("123fj"); session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); session.connect();
session.setPassword(""); session.setConfig("StrictHostKeyChecking", "no"); session.connect();
session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); session.connect();
session.setPassword(password);
this.session.setPassword(password);
session.setPassword(password);
ses.setPassword(spec.password());
private Session newJSchSession() throws JSchException { JSch jsch = new JSch(); if (identityPath != null) { jsch.addIdentity(identityPath); } Session session = jsch.getSession(username, hostname, 22); if (password != null) { session.setPassword(password); } session.setConfig("StrictHostKeyChecking", "no"); return session; }
JSch jsch = new JSch(); Session session = jsch.getSession( user, host, port ); session.setConfig( "PreferredAuthentications", "password" ); session.setPassword( pass ); session.connect( FTP_TIMEOUT ); Channel channel = session.openChannel( "sftp" ); ChannelSftp sftp = ( ChannelSftp ) channel; sftp.connect( FTP_TIMEOUT );
sshTunnelingConfiguration.getProxyPassword()); } else { session.setPassword(password);
private ChannelSftp openSSHConnection(Server server) throws Exception { logger.debug("Opening SSH connection to {}@{}", server.getUsername(), server.getHostname()); JSch jsch = new JSch(); Session session = jsch.getSession(server.getUsername(), server.getHostname(), server.getPort()); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); if (server.getPemPath() != null) { jsch.addIdentity(server.getPemPath()); } session.setConfig(config); if (server.getPassword() != null) { session.setPassword(server.getPassword()); } session.connect(); //Open a new session for SFTP. Channel channel = session.openChannel("sftp"); channel.connect(); //checking SSH client connection. if (!channel.isConnected()) { logger.warn("Cannot connect with SSH to {}@{}", server.getUsername(), server.getHostname()); throw new RuntimeException("Can not connect to " + server.getUsername() + "@" + server.getHostname()); } logger.debug("SSH connection successful"); return (ChannelSftp) channel; } }