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.setTimeout(connectionTimeoutMillis); session.connect(); this.session = session; session.setTimeout(ctx.getProperty(FileTransfer.DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()); if (!ctx.getProperty(USE_KEEPALIVE_ON_TIMEOUT).asBoolean()) { session.setServerAliveCountMax(0); // do not send keepalive message on SocketTimeoutException
jschSession.setTimeout(this.timeout);
/** * Sets the interval to send a keep-alive message. If zero is * specified, any keep-alive message must not be sent. The default interval * is zero. * * @param interval the specified interval, in milliseconds. * @see #getServerAliveInterval() */ public void setServerAliveInterval(int interval) throws JSchException { setTimeout(interval); this.serverAliveInterval=interval; }
public void setServerAliveInterval(int interval) throws JSchException { setTimeout(interval); this.serverAliveInterval=interval; } public void setServerAliveCountMax(int count){
/** * Sets the interval to send a keep-alive message. If zero is * specified, any keep-alive message must not be sent. The default interval * is zero. * * @param interval the specified interval, in milliseconds. * @see #getServerAliveInterval() */ public void setServerAliveInterval(int interval) throws JSchException { setTimeout(interval); this.serverAliveInterval=interval; }
/** * Sets the interval to send a keep-alive message. If zero is * specified, any keep-alive message must not be sent. The default interval * is zero. * * @param interval the specified interval, in milliseconds. * @see #getServerAliveInterval() */ public void setServerAliveInterval(int interval) throws JSchException { setTimeout(interval); this.serverAliveInterval = interval; }
/** * sets the server alive interval property. * This is also as the {@link #setTimeout timeout} value * (and nowhere else). If zero is * specified, no keep-alive message must be sent. The default interval * is zero. * * @param interval the timeout interval in milliseconds before sending * a server alive message, if no message is received from the server. * @see #getServerAliveInterval() */ public void setServerAliveInterval(int interval) throws JSchException { setTimeout(interval); this.serverAliveInterval=interval; }
public void setTimeout(int timeout) throws IOException { try { session.setTimeout(timeout); } catch (JSchException e) { IOException ioe = new IOException("Failed to set timeout."); ioe.initCause(e); throw ioe; } }
private Session createSSHSession(String host) throws JSchException { Session newSession = jsch.getSession(sshUser, host, 22); newSession.setTimeout(500); Properties props = new Properties(); props.put("StrictHostKeyChecking", "no"); newSession.setConfig(props); newSession.connect(); return newSession; }
public Session openSession() throws JSchException { JSch jsch = new JSch(); Session session = jsch.getSession(user, host, port); UserInfo ui = new SSHUserInfo(password); session.setUserInfo(ui); session.setTimeout(timeout); session.connect(timeout); return session; } }
private ChannelSftp openChannel() throws JSchException { if (channel == null || !channel.isConnected()) { JSch jsch = new JSch(); int port = uri.getPort() <= 0 ? 22 : uri.getPort(); com.jcraft.jsch.Session session = jsch.getSession(username, uri.getHost(), port); session.setConfig("StrictHostKeyChecking", "no"); session.setTimeout(timeout); session.setPassword(password); session.connect(); channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); // If this object opened the channel it should probably be the one closing it too keepChannelOpen = false; } return channel; }
JSch jsch = new JSch(); Properties properties = new Properties(); properties.setProperty("StrictHostKeyChecking", "no"); if (privKeyFile != null) jsch.addIdentity(privKeyFile, password); Session session = jsch.getSession(username, host, port); session.setTimeout(timeout); session.setConfig(properties); if (proxy != null) session.setProxy(proxy); if (privKeyFile == null && password != null) session.setPassword(password); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect();
/** * Create a new remote session for the requested address. * * @param user * login to authenticate as. * @param host * server name to connect to. * @param port * port number of the SSH daemon (typically 22). * @return new session instance, but otherwise unconfigured. * @throws JSchException * the session could not be created. */ private Session createSession(JSch jsch, String user, String host, int port) throws JSchException { final Session session = jsch.getSession(user, host, port); // We retry already in getSession() method. JSch must not retry // on its own. session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$ session.setTimeout(Integer.parseInt(configReader.getConfiguration(SSH_SESSION_TIMEOUT))); java.util.Properties config = this.configReader.getProperties(); session.setConfig(config); return session; } private static void knownHosts(final JSch sch,final File home) throws JSchException {
private Session startSession() { try { Session session = openSession(); session.setTimeout((int) maxwait); session.setPortForwardingL(Integer.parseInt(lport), rhost, Integer.parseInt(rport)); log("SSHTunnel : Connection created successfully.", Project.MSG_INFO); return session; } catch (Exception e) { log("SSHTunnel : Connect Failed", Project.MSG_ERR); throw new BuildException("SSHTunnel Task Failed: Unable to create tunnel", e); } }
private void newSession() throws JSchException { JSch jsch = new JSch(); session = null; try { session = jsch.getSession(username, host, port); if (timeout != 0) session.setTimeout(timeout); logger.debug("%s@%s:%d: Session created.", username, host, port); if (password != null) { session.setPassword(password); } else { // jsch wipes out your private key jsch.addIdentity(username, Arrays.copyOf(privateKey, privateKey.length), null, emptyPassPhrase); } } catch (JSchException e) { throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host, port), e); } java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); logger.debug("%s@%s:%d: Session connected.", username, host, port); }
@Override public Session create() throws Exception { JSch jsch = new JSch(); session = jsch .getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22)); if (sessionTimeout != 0) session.setTimeout(sessionTimeout); if (loginCredentials.getPrivateKey() == null) { session.setPassword(loginCredentials.getPassword()); } else { checkArgument(!loginCredentials.getPrivateKey().contains("Proc-Type: 4,ENCRYPTED"), "JschSshClientModule does not support private keys that require a passphrase"); byte[] privateKey = loginCredentials.getPrivateKey().getBytes(); jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase); } java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); if (proxy.isPresent()) session.setProxy(proxy.get()); session.connect(connectTimeout); return session; }
@Override public Session create() throws Exception { JSch jsch = new JSch(); session = jsch .getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22)); if (sessionTimeout != 0) session.setTimeout(sessionTimeout); if (loginCredentials.hasUnencryptedPrivateKey()) { byte[] privateKey = loginCredentials.getOptionalPrivateKey().get().getBytes(); jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase); } else if (loginCredentials.getOptionalPassword().isPresent()) { session.setPassword(loginCredentials.getOptionalPassword().orNull()); } else if (agentConnector.isPresent()) { JSch.setConfig("PreferredAuthentications", "publickey"); jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get())); } java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); if (proxy.isPresent()) session.setProxy(proxy.get()); session.connect(connectTimeout); return session; }
private void login() throws Exception { provider.connect(); verify(jsch).setKnownHosts(hostFile.getAbsolutePath()); verify(session).setTimeout(new Long(SECONDS.toMillis(TIMEOUT)).intValue()); verify(session).connect(); verify(channel).connect(); Properties properties = captureLoginProperties(); assertThat(properties.getProperty(PREFERRED_AUTHENTICATION_METHODS), equalTo(GSSAPI_WITH_MIC.toString())); assertThat(properties.getProperty(STRICT_HOST_KEY_CHECKING), equalTo("ask")); }
@Override public void connect(NetconfConnectionDetails connectionDetails) throws APPCException { String host = connectionDetails.getHost(); int port = connectionDetails.getPort(); String username = connectionDetails.getUsername(); String password = connectionDetails.getPassword(); try { JSch.setLogger(new JSchLogger()); JSch jsch = new JSch(); session = jsch.getSession(EncryptionTool.getInstance().decrypt(username), host, port); session.setPassword(EncryptionTool.getInstance().decrypt(password)); session.setConfig("StrictHostKeyChecking", "no"); Properties additionalProps = connectionDetails.getAdditionalProperties(); if((additionalProps != null) && !additionalProps.isEmpty()) { session.setConfig(additionalProps); } session.connect(SESSION_CONNECT_TIMEOUT); session.setTimeout(10000); createConnection(connectionDetails); } catch(Exception e) { String message = EELFResourceManager.format(Msg.CANNOT_ESTABLISH_CONNECTION, host, String.valueOf(port), username); throw new APPCException(message, e); } }