com.jcraft.jsch.Session.setServerAliveInterval()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(770)

本文整理了Java中com.jcraft.jsch.Session.setServerAliveInterval()方法的一些代码示例,展示了Session.setServerAliveInterval()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.setServerAliveInterval()方法的具体详情如下:
包路径:com.jcraft.jsch.Session
类名称:Session
方法名:setServerAliveInterval

Session.setServerAliveInterval介绍

[英]sets the server alive interval property. This is also as the #setTimeout value (and nowhere else). If zero is specified, no keep-alive message must be sent. The default interval is zero.
[中]设置服务器活动间隔属性。这也是#setTimeout值(而不是其他值)。如果指定了零,则不必发送保持活动状态的消息。默认间隔为零。

代码示例

代码示例来源:origin: spring-projects/spring-integration

jschSession.setServerAliveInterval(this.serverAliveInterval);

代码示例来源:origin: org.rundeck/rundeck-core

private static void configureSessionServerAliveInterval(Map<String, String> config, Session session) throws JSchException {
  String serverAliveInterval = config.get(SSH_CONFIG_SERVER_ALIVE_INTERVAL);
  if (serverAliveInterval != null) {
    try {
      session.setServerAliveInterval(Integer.parseInt(serverAliveInterval) * 1000);
    } catch (NumberFormatException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

private Session getRemoteSession(String userName, String password, String dnsName, int sshPort) throws JSchException {
  LOGGER.log(Level.INFO,
      "AzureVMAgentSSHLauncher: getRemoteSession: getting remote session for user {0} to host {1}:{2}",
      new Object[]{userName, dnsName, sshPort});
  JSch remoteClient = new JSch();
  try {
    final Session session = remoteClient.getSession(userName, dnsName, sshPort);
    session.setConfig("StrictHostKeyChecking", "no");
    session.setPassword(password);
    // pinging server for every 1 minutes to keep the connection alive
    final int serverAliveIntervalInMillis = 60 * 1000;
    session.setServerAliveInterval(serverAliveIntervalInMillis);
    session.connect();
    LOGGER.log(Level.INFO,
        "AzureVMAgentSSHLauncher: getRemoteSession: Got remote session for user {0} to host {1}:{2}",
        new Object[]{userName, dnsName, sshPort});
    return session;
  } catch (JSchException e) {
    LOGGER.log(Level.SEVERE,
        String.format("AzureVMAgentSSHLauncher: getRemoteSession: "
                + "Got exception while connecting to remote host %s:%s",
            dnsName, sshPort), e);
    throw e;
  }
}

代码示例来源:origin: com.dell.cpsd/common-client

public void openConnection(int keepAliveInMili) throws IOException
{
  try
  {
    session = jsch.getSession(username, hostname, port);
    session.setServerAliveInterval(keepAliveInMili);
  }
  catch (JSchException e)
  {
    throw new IOException(String.format("Could not getSession for %s", hostname), e);
  }
  Properties config = new Properties();
  config.put("StrictHostKeyChecking", "no");
  //config.put("PreferredAuthentications", "password");
  session.setConfig(config);
  session.setPassword(password);
  try
  {
    session.connect();
  }
  catch (JSchException e)
  {
    throw new IOException(String.format("Could not connect session for %s", hostname), e);
  }
}

代码示例来源:origin: apache/lens

config.put("StrictHostKeyChecking", "no");
session.setServerAliveInterval(10000);
session.setConfig(config);
session.connect(0);

代码示例来源:origin: jenkinsci/ssh-plugin

private Session createSession(final PrintStream logger) throws JSchException, IOException, InterruptedException {
  final StandardUsernameCredentials user = lookupCredentialsById(credentialId);
  if (user == null) {
    String message = "Credentials with id '" + credentialId + "', no longer exist!";
    logger.println(message);
    throw new InterruptedException(message);
  }
  final JSchConnector connector = new JSchConnector(user.getUsername(), getResolvedHostname(), port);
  final SSHAuthenticator<JSchConnector, StandardUsernameCredentials> authenticator = SSHAuthenticator
      .newInstance(connector, user);
  authenticator.authenticate(new StreamTaskListener(logger, Charset.defaultCharset()));
  final Session session = connector.getSession();
  session.setServerAliveInterval(serverAliveInterval);
  final Properties config = new Properties();
  //TODO put this as configuration option instead of ignoring by default
  config.put("StrictHostKeyChecking", "no");
  session.setConfig(config);
  session.connect(timeout);
  return session;
}

代码示例来源:origin: asakusafw/asakusafw

session.setServerAliveInterval((int) TimeUnit.SECONDS.toMillis(30));

代码示例来源:origin: org.hudsonci.plugins/gerrit-events

/**
 * Creates and opens a SshConnection.
 *
 * @param host           the host to connect to.
 * @param port           the port.
 * @param authentication the authentication-info
 * @throws SshException if something happens - usually due to bad config.
 * @throws IOException  if the unfortunate happens.
 */
protected SshConnectionImpl(String host, int port, Authentication authentication) throws SshException, IOException {
  logger.debug("connecting...");
  try {
    client = new JSch();
    client.addIdentity(authentication.getPrivateKeyFile().getAbsolutePath(),
        authentication.getPrivateKeyFilePassword());
    client.setHostKeyRepository(new BlindHostKeyRepository());
    connectSession = client.getSession(authentication.getUsername(), host, port);
    connectSession.connect();
    logger.debug("Connected: {}", connectSession.isConnected());
    connectSession.setServerAliveInterval(ALIVE_INTERVAL);
  } catch (JSchException ex) {
    throw new SshException(ex);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

session.setServerAliveInterval(keepAliveInterval);

代码示例来源:origin: ixrjog/opsCloud

session.setServerAliveInterval(SERVER_ALIVE_INTERVAL);
session.connect(SESSION_TIMEOUT);

代码示例来源:origin: sonyxperiadev/gerrit-events

connectSession.setServerAliveInterval(ALIVE_INTERVAL);
} catch (JSchException ex) {
  throw new SshException(ex);

代码示例来源:origin: org.springframework.integration/spring-integration-sftp

jschSession.setServerAliveInterval(this.serverAliveInterval);

代码示例来源:origin: jcabi/jcabi-ssh

this.getLogin(), this.getAddr(), this.getPort()
);
session.setServerAliveInterval(
  (int) TimeUnit.SECONDS.toMillis(Tv.TEN)
);

代码示例来源:origin: com.jcabi/jcabi-ssh

this.getLogin(), this.getAddr(), this.getPort()
);
session.setServerAliveInterval(
  (int) TimeUnit.SECONDS.toMillis(Tv.TEN)
);

代码示例来源:origin: com.jcabi/jcabi-ssh

);
session.setPassword(this.password);
session.setServerAliveInterval(
  (int) TimeUnit.SECONDS.toMillis(Tv.TEN)
);

代码示例来源:origin: jcabi/jcabi-ssh

);
session.setPassword(this.password);
session.setServerAliveInterval(
  (int) TimeUnit.SECONDS.toMillis(Tv.TEN)
);

代码示例来源:origin: cisco-ie/anx

session.setDaemonThread(true);
session.setTimeout(timeout);
session.setServerAliveInterval(keepalive);
session.setConfig("StrictHostKeyChecking", strictHostKeyChecking ? "yes" : "no");

代码示例来源:origin: org.apache.ant/ant-jsch

session.setServerAliveInterval(getServerAliveIntervalSeconds() * 1000);

代码示例来源:origin: asakusafw/asakusafw

session = jsch.getSession(profile.getUser(), profile.getHost(), profile.getPort());
session.setConfig("StrictHostKeyChecking", "no");
session.setServerAliveInterval((int) TimeUnit.SECONDS.toMillis(10));
session.setTimeout((int) TimeUnit.SECONDS.toMillis(60));

代码示例来源:origin: com.github.robtimus/sftp-fs

int interval = FileSystemProviderSupport.getIntValue(this, SERVER_ALIVE_INTERVAL);
try {
  session.setServerAliveInterval(interval);
} catch (JSchException e) {
  throw asFileSystemException(e);

相关文章

微信公众号

最新文章

更多