本文整理汇总了Java中com.jcraft.jsch.Session.setTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setTimeout方法的具体用法?Java Session.setTimeout怎么用?Java Session.setTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.Session
的用法示例。
在下文中一共展示了Session.setTimeout方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openSession
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
protected Session openSession(final ProcessContext context) throws JSchException {
final JSch jsch = new JSch();
final String hostKeyVal = context.getProperty(HOST_KEY_FILE).getValue();
if (hostKeyVal != null) {
jsch.setKnownHosts(hostKeyVal);
}
final Session session = jsch.getSession(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue(),
context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue(),
context.getProperty(PORT).evaluateAttributeExpressions().asInteger().intValue());
final Properties properties = new Properties();
properties.setProperty("StrictHostKeyChecking", context.getProperty(STRICT_HOST_KEY_CHECKING).asBoolean() ? "yes" : "no");
properties.setProperty("PreferredAuthentications", "publickey,password,keyboard-interactive");
final PropertyValue compressionValue = context.getProperty(USE_COMPRESSION);
if (compressionValue != null && "true".equalsIgnoreCase(compressionValue.getValue())) {
properties.setProperty("compression.s2c", "[email protected],zlib,none");
properties.setProperty("compression.c2s", "[email protected],zlib,none");
} else {
properties.setProperty("compression.s2c", "none");
properties.setProperty("compression.c2s", "none");
}
session.setConfig(properties);
final String privateKeyFile = context.getProperty(PRIVATE_KEY_PATH).evaluateAttributeExpressions().getValue();
if (privateKeyFile != null) {
jsch.addIdentity(privateKeyFile, context.getProperty(PRIVATE_KEY_PASSPHRASE).evaluateAttributeExpressions().getValue());
}
final String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
if (password != null) {
session.setPassword(password);
}
session.setTimeout(context.getProperty(CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());
session.connect();
return session;
}
示例2: create
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
@Override
public Session create(ServerDetails serverDetails) throws Exception {
Session session = null;
try {
JSch jsch = new JSch();
if (serverDetails.getPrivateKeyLocation() != null) {
jsch.addIdentity(serverDetails.getPrivateKeyLocation());
}
session = jsch.getSession(serverDetails.getUser(), serverDetails.getHost(), serverDetails.getPort());
session.setConfig("StrictHostKeyChecking", "no"); //
UserInfo userInfo = new JschUserInfo(serverDetails.getUser(), serverDetails.getPassword());
session.setUserInfo(userInfo);
session.setTimeout(60000);
session.setPassword(serverDetails.getPassword());
session.connect();
} catch (Exception e) {
throw new RuntimeException(
"ERROR: Unrecoverable error when trying to connect to serverDetails : "
+ serverDetails, e);
}
return session;
}
示例3: connect
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
/**
* 连接到服务器
*/
private static Session connect(String host,String user,String pass) throws JSchException{
JSch sch = new JSch();
Session session = sch.getSession(user, host, 22);
session.setPassword(pass);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setTimeout(60000);
session.connect();
return session;
}
示例4: connect
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
/**
* 连接到服务器
*/
private Session connect() throws JSchException{
JSch sch = new JSch();
Session session = sch.getSession(user, this.hosts, 22);
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setTimeout(60000);
session.connect();
return session;
}
示例5: openExecChannel
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
protected Channel openExecChannel(final ProcessContext context, final Session session, final String command) throws JSchException {
ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(command);
session.setTimeout(context.getProperty(DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());
if (!context.getProperty(USE_KEEPALIVE_ON_TIMEOUT).asBoolean()) {
session.setServerAliveCountMax(0); // do not send keepalive message on SocketTimeoutException
}
return channel;
}
示例6: main
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public static void main( String[] args )
{
String hostname = null;
int port = 22;
String username = null;
String password = null;
int timeout = 20000;
Properties config = new java.util.Properties();
config.put( "StrictHostKeyChecking", "no" );
for ( int i = 0; i < args.length; i++ )
{
if ( args[i].equalsIgnoreCase( "-host" ) )
{
hostname = args[i + 1];
i++;
}
else if ( args[i].equalsIgnoreCase( "-port" ) )
{
port = Integer.parseInt( args[i + 1] );
i++;
}
else if ( args[i].equalsIgnoreCase( "-username" ) )
{
username = args[i + 1];
i++;
}
else if ( args[i].equalsIgnoreCase( "-password" ) )
{
password = args[i + 1];
i++;
}
}
if ( hostname == null )
{
logger.error( "Hostname cannot be null." );
}
else if ( username == null )
{
logger.error( "Username cannot be null." );
}
else if ( password == null )
{
logger.error( "Password cannot be null." );
}
long start = System.currentTimeMillis();
logger.info( "Start of processing." );
JSch jsch = new JSch();
try
{
Session session = jsch.getSession( username, hostname, port );
session.setPassword( password );
session.setDaemonThread( true );
session.setConfig( config );
logger.info( "Session default timeout " + session.getTimeout() );
session.setTimeout( timeout );
logger.info( "Session created after " + ( System.currentTimeMillis() - start ) / 1000.0 + " seconds." );
session.connect();
logger.info( "Connection established after " + ( System.currentTimeMillis() - start ) / 1000.0
+ " seconds." );
}
catch ( JSchException e )
{
logger.info( "Connection aborted after " + ( System.currentTimeMillis() - start ) / 1000.0 + " seconds." );
logger.error( "Received exception.", e );
}
}
示例7: connect
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public int connect(String sshTunnelHost, String host, int port, int localPort) {
Assert.notNull(sshTunnelHost, "sshTunnelHost must not be null");
Assert.notNull(host, "host must not be null");
Assert.isTrue(port > 0, "illegal port: " + port);
Assert.isTrue(localPort >= 0, "illegal local port: " + localPort);
log.debug("tunneling to {}:{} via {}", host, port, sshTunnelHost);
try {
sshConfiguration.addIdentity(sshTunnelHost);
SshProxyConfig proxyConfig = sshConfiguration.getProxyConfiguration(sshTunnelHost);
if (proxyConfig == null) {
return directConnect(sshTunnelHost, host, port, localPort);
}
int jumpPort = connect(proxyConfig);
String hostUser = sshConfiguration.getHostUser(sshTunnelHost);
String jumpHost = proxyConfig.getJumpHost();
Session jumpHostSession = sshConfiguration.openSession(hostUser, jumpHost, jumpPort);
String hostname = sshConfiguration.getHostName(sshTunnelHost);
jumpHostSession.setHostKeyAlias(hostname);
sshSessions.push(jumpHostSession);
jumpHostSession.setTimeout(timeoutMillis);
jumpHostSession.connect(timeoutMillis);
log.debug("[{}] connected via {}@localhost:{}", sshTunnelHost, hostUser, jumpPort);
return addLocalPortForwarding(sshTunnelHost, jumpHostSession, host, port, localPort);
} catch (Exception e) {
throw new SshProxyRuntimeException("Failed to create SSH tunnel to " + host + " via " + sshTunnelHost, e);
}
}
示例8: directConnect
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private int directConnect(String jumpHost, String targetHost, int targetPort, int localPort) throws JSchException {
Session jumpHostSession = sshConfiguration.openSession(jumpHost);
sshSessions.add(jumpHostSession);
jumpHostSession.setTimeout(timeoutMillis);
try {
jumpHostSession.connect(timeoutMillis);
} catch (JSchException e) {
log.debug("Failed to connect to {} via {}", targetHost, jumpHost, e);
throw new SshProxyRuntimeException("Failed to connect to " + targetHost + " via " + jumpHost);
}
log.debug("[{}] connected", jumpHost);
return addLocalPortForwarding(jumpHost, jumpHostSession, targetHost, targetPort, localPort);
}
示例9: create
import com.jcraft.jsch.Session; //导入方法依赖的package包/类
/**
* Connect to remote SSH endpoint specified by {@code url}.
*
* @throws JSchException if we fail to open the connection.
*/
JSchSshSession create(JSch jsch, URI uri) throws JSchException {
RdeUploadUrl url = RdeUploadUrl.create(uri);
logger.info("Connecting to SSH endpoint: " + url);
Session session = jsch.getSession(
url.getUser().orElse("domain-registry"),
url.getHost(),
url.getPort());
if (url.getPass().isPresent()) {
session.setPassword(url.getPass().get());
}
session.setTimeout((int) sshTimeout.getMillis());
session.connect((int) sshTimeout.getMillis());
return new JSchSshSession(session, url, (int) sshTimeout.getMillis());
}