当前位置: 首页>>代码示例>>Java>>正文


Java Session.setConfig方法代码示例

本文整理汇总了Java中com.jcraft.jsch.Session.setConfig方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setConfig方法的具体用法?Java Session.setConfig怎么用?Java Session.setConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcraft.jsch.Session的用法示例。


在下文中一共展示了Session.setConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileFetch

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public static void fileFetch(String host, String user, String keyLocation, String sourceDir, String destDir) {
    JSch jsch = new JSch();
    Session session = null;
    try {
        // set up session
        session = jsch.getSession(user,host);
        // use private key instead of username/password
        session.setConfig(
                "PreferredAuthentications",
                "publickey,gssapi-with-mic,keyboard-interactive,password");
        jsch.addIdentity(keyLocation);
        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();

        // copy remote log file to localhost.
        ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
        channelSftp.connect();
        channelSftp.get(sourceDir, destDir);
        channelSftp.exit();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.disconnect();
    }
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:29,代码来源:SshUtils.java

示例2: executeCommand

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public void executeCommand(final String command) throws IOException { // Cliente SSH final
    JSch jsch = new JSch();
    Properties props = new Properties();
    props.put("StrictHostKeyChecking", "no");
    try {
        Session session = jsch.getSession(user, host, 22);
        session.setConfig(props);
        session.setPassword(password);
        session.connect();
        java.util.logging.Logger.getLogger(RemoteShell.class.getName())
                .log(Level.INFO, session.getServerVersion());

        Channel channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);
        // Daqui para baixo é somente para imprimir a saida
        channel.setInputStream(null);

        ((ChannelExec) channel).setErrStream(System.err);

        InputStream in = channel.getInputStream();

        channel.connect();

        byte[] tmp = new byte[1024];
        while (true) {
            while (in.available() > 0) {
                int i = in.read(tmp, 0, 1024);
                if (i < 0) {
                    break;
                }
                System.out.print(new String(tmp, 0, i));
            }
            if (channel.isClosed()) {
                if (in.available() > 0) {
                    continue;
                }
                System.out
                        .println("exit-status: " + channel.getExitStatus());
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (Exception ee) {
            }
        }
        channel.disconnect();
        session.disconnect();

    } catch (JSchException ex) {
        java.util.logging.Logger.getLogger(RemoteShell.class.getName())
                .log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:nailtonvieira,项目名称:pswot-cloud-java-spring-webapp,代码行数:54,代码来源:RemoteShell.java

示例3: connectAndExecute

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public static String connectAndExecute(String user, String host, String password, String command1) {
	String CommandOutput = null;
	try {

		java.util.Properties config = new java.util.Properties();
		config.put("StrictHostKeyChecking", "no");
		JSch jsch = new JSch();

		Session session = jsch.getSession(user, host, 22);
		session.setPassword(password);
		session.setConfig(config);
		session.connect();
		// System.out.println("Connected");

		Channel channel = session.openChannel("exec");
		((ChannelExec) channel).setCommand(command1);
		channel.setInputStream(null);
		((ChannelExec) channel).setErrStream(System.err);

		InputStream in = channel.getInputStream();

		channel.connect();
		byte[] tmp = new byte[1024];
		while (true) {
			while (in.available() > 0) {
				int i = in.read(tmp, 0, 1024);

				if (i < 0)
					break;
				// System.out.print(new String(tmp, 0, i));
				CommandOutput = new String(tmp, 0, i);
			}

			if (channel.isClosed()) {
				// System.out.println("exit-status: " +
				// channel.getExitStatus());
				break;
			}
			try {
				Thread.sleep(1000);
			} catch (Exception ee) {
			}
		}
		channel.disconnect();
		session.disconnect();
		// System.out.println("DONE");

	} catch (Exception e) {
		e.printStackTrace();
	}
	return CommandOutput;

}
 
开发者ID:saiscode,项目名称:kheera,代码行数:54,代码来源:SeleniumGridManager.java

示例4: createSession

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:SshFenceByTcpPort.java

示例5: testJschConnection

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
@Test
public void testJschConnection() throws InterruptedException, SftpException, JSchException, IOException {
    JSch jsch = new JSch();
    String passphrase = "";
    jsch.addIdentity(privateKey,
        StringUtil.isEmpty(passphrase) ?
        null : passphrase);

    Session session = jsch.getSession(user, host, port);
    System.out.println("session created.");

    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    config.put("PreferredAuthentications",
        "publickey,keyboard-interactive,password");
    session.setConfig(config);
    session.connect();
    Thread.sleep(500);
    session.disconnect();
}
 
开发者ID:sanchouss,项目名称:InstantPatchIdeaPlugin,代码行数:21,代码来源:RemoteClientImplTest.java

示例6: executeSSH

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private boolean executeSSH(){ 
	//get deployment descriptor, instead of this hard coded.
	// or execute a script on the target machine which download artifact from nexus
       String command ="nohup java -jar -Dserver.port=8091 ./work/codebox/chapter6/chapter6.search/target/search-1.0.jar &";
      try{	
   	   System.out.println("Executing "+ command);
          java.util.Properties config = new java.util.Properties(); 
          config.put("StrictHostKeyChecking", "no");
          JSch jsch = new JSch();
          Session session=jsch.getSession("rajeshrv", "localhost", 22);
          session.setPassword("rajeshrv");
          
          session.setConfig(config);
          session.connect();
          System.out.println("Connected");
           
          ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
          InputStream in = channelExec.getInputStream();
          channelExec.setCommand(command);
          channelExec.connect();
         
          BufferedReader reader = new BufferedReader(new InputStreamReader(in));
          String line;
          int index = 0;

          while ((line = reader.readLine()) != null) {
              System.out.println(++index + " : " + line);
          }
          channelExec.disconnect();
          session.disconnect();

          System.out.println("Done!");

      }catch(Exception e){
          e.printStackTrace();
          return false;
      }
	
	return true;
}
 
开发者ID:rajeshrv,项目名称:SpringMicroservice,代码行数:41,代码来源:DeploymentEngine.java

示例7: create

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
@Override
public Session create(ConnectionDetails connectionDetails) throws Exception {
    log.debug("Creating session for "+connectionDetails);
    Session session = null;
    try {
        byte[] privateKey = connectionDetails.getPrivateKey();
        if (privateKey != null) {
            jsch.addIdentity(connectionDetails.getUsername(), privateKey, null, connectionDetails.getPassword().getBytes());
        }
        session = jsch.getSession(connectionDetails.getUsername(), connectionDetails.getHost(), connectionDetails.getPort());
        session.setPassword(connectionDetails.getPassword());
        if (!hostKeyValidation) {
            session.setConfig("StrictHostKeyChecking", "no");
        }
        session.setDaemonThread(true);
        session.connect();
    } catch (Exception e) {
        log.error("Failed to connect to "+connectionDetails);
        throw e;
    }
    return session;
}
 
开发者ID:tilln,项目名称:jmeter-sshmon,代码行数:23,代码来源:SSHSessionFactory.java

示例8: configureSession

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session configureSession() {
    try {
        //configure the tunnel
        log.info("Configuring SSH tunnel");
        Session session = jsch.getSession(
                sshDetails.user,
                sshDetails.host,
                sshDetails.sshPort
        );

        jsch.addIdentity(sshDetails.keyFile.getPath(), sshDetails.passphrase);

        final Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        config.put("ConnectionAttempts", "3");
        //dont set the keep alive too low or you might suffer from a breaking connection during start up (for whatever reason)
        session.setServerAliveInterval(1000);//milliseconds
        session.setConfig(config);

        //forward the port
        final int assignedPort = session.setPortForwardingL(
                sshDetails.localPort,
                "localhost",
                sshDetails.remotePort
        );
        log.info("Setting up port forwarding: localhost:" + assignedPort + " -> " + sshDetails.host + ":" + sshDetails.remotePort);

        return session;
    } catch (final JSchException e) {
        throw new RuntimeException("Failed to configure SSH tunnel", e);
    }
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:33,代码来源:SshTunnel.java

示例9: validateCredentials

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public Message validateCredentials(String host, String user, String password) {

		JSch jsch = new JSch();

		Session session;
		try {
			session = jsch.getSession(user, host, SSH_PORT);

			session.setPassword(password);

			java.util.Properties config = new java.util.Properties();
			config.put(STRICT_HOST_KEY_CHECKING, STRICT_HOST_KEY_CHECKING_DEFAULT_VALUE);
			session.setConfig(config);

			session.setConfig(PREFERRED_AUTHENTICATIONS, PREFERRED_AUTHENTICATIONS_DEFAULT_VALUES);

			session.connect();
			session.disconnect();
		} catch (Exception e) {
			return getErrorMessage(e);
		}

		return new Message(MessageType.SUCCESS, GENERAL_SUCCESS_MESSAGE);
	}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:25,代码来源:SCPUtility.java

示例10: deleteFile

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
/**
 * @param host
 * @param user
 * @param pwd
 * @param remoteFile
 */
public void deleteFile(String host, String user, String pwd,
		String remoteFile) {
	try {
		JSch ssh = new JSch();
		Session session = ssh.getSession(user, host, 22);

		java.util.Properties config = new java.util.Properties();
		config.put("StrictHostKeyChecking", "no");
		session.setConfig(config);
		session.setPassword(pwd);

		session.connect();
		Channel channel = session.openChannel("exec");
		channel.connect();

		String command = "rm -rf " + remoteFile;
		System.out.println("command: " + command);
		// ((ChannelExec) channel).setCommand(command);

		channel.disconnect();
		session.disconnect();
	} catch (JSchException e) {
		System.out.println(e.getMessage().toString());
		e.printStackTrace();
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:33,代码来源:ScpFrom.java

示例11: initSessionFactory

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private void initSessionFactory() {
    JschConfigSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(Host host, Session session) {
            session.setConfig("StrictHostKeyChecking", "no");
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            JSch jSch = super.createDefaultJSch(fs);

            // apply customized private key
            if (privateKeyPath != null) {
                jSch.removeAllIdentity();
                jSch.addIdentity(privateKeyPath.toString());
            }

            return jSch;
        }
    };

    transportConfigCallback = transport -> {
        SshTransport sshTransport = (SshTransport) transport;
        sshTransport.setSshSessionFactory(sshSessionFactory);
    };
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:27,代码来源:GitSshClient.java

示例12: connect

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
public static Session connect(String host, Integer port, String user, String password) throws JSchException{
	Session session = null;
	try {
		JSch jsch = new JSch();
		if(port != null){
			session = jsch.getSession(user, host, port.intValue());
		}else{
			session = jsch.getSession(user, host);
		}
		session.setPassword(password);
		
		session.setConfig("StrictHostKeyChecking", "no");
		//time out
		session.connect(3000);
	} catch (JSchException e) {
		e.printStackTrace();
		System.out.println("SFTPUitl connection error");
		throw e;
	}
	return session;
}
 
开发者ID:zhuyuqing,项目名称:BestConfig,代码行数:22,代码来源:SFTPUtil.java

示例13: createSession

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session createSession(CredentialsProvider credentialsProvider,
                              FS fs, String user, final String pass, String host, int port,
                              final OpenSshConfig.Host hc) throws JSchException {
    final Session session = createSession(credentialsProvider, hc, user, host, port, fs);
    // We retry already in getSession() method. JSch must not retry
    // on its own.
    session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$
    if (pass != null)
        session.setPassword(pass);
    final String strictHostKeyCheckingPolicy = hc
            .getStrictHostKeyChecking();
    if (strictHostKeyCheckingPolicy != null)
        session.setConfig("StrictHostKeyChecking", //$NON-NLS-1$
                strictHostKeyCheckingPolicy);
    final String pauth = hc.getPreferredAuthentications();
    if (pauth != null)
        session.setConfig("PreferredAuthentications", pauth); //$NON-NLS-1$
    if (credentialsProvider != null && !(credentialsProvider instanceof PrivateKeyCredentialsProvider)
            && (!hc.isBatchMode() || !credentialsProvider.isInteractive())) {
        session.setUserInfo(new CredentialsProviderUserInfo(session,
                credentialsProvider));
    }
    configure(hc, session);
    return session;
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:26,代码来源:MultiUserSshSessionFactory.java

示例14: exec

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
@SneakyThrows
public static int exec(@Nonnull String host,
                       int port,
                       @Nonnull String username,
                       @Nonnull String password,
                       @Nonnull String cmd) {
    JSch jSch = new JSch();

    Session session = jSch.getSession(username, host, port);
    session.setPassword(password);
    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect();
    Channel channel = session.openChannel("exec");
    ((ChannelExec) channel).setCommand(cmd);
    ((ChannelExec) channel).setInputStream(null);
    ((ChannelExec) channel).setErrStream(System.err);
    InputStream inputStream = channel.getInputStream();
    channel.connect();

    log.info("# successful connect to server [{}:{}]", host, port);

    log.info("# exec cmd [{}]", cmd);

    StringBuilder sb = new StringBuilder();
    byte[] bytes = new byte[1024];
    int exitStatus;
    while (true) {
        while (inputStream.available() > 0) {
            int i = inputStream.read(bytes, 0, 1024);
            if (i < 0) {
                break;
            }
            sb.append(new String(bytes, 0, i, StandardCharsets.UTF_8));
        }
        if (channel.isClosed()) {
            if (inputStream.available() > 0) {
                continue;
            }
            exitStatus = channel.getExitStatus();
            break;
        }
        Thread.sleep(1000);
    }
    if (StringUtils.isNotEmpty(sb)) {
        log.info("# cmd-rs \n" + sb);
    }
    channel.disconnect();
    session.disconnect();

    log.info("# successful disconnect to server [{}:{}]", host, port);

    return exitStatus;
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:56,代码来源:TcSshBin.java

示例15: 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;
}
 
开发者ID:danielemaddaluno,项目名称:command4j,代码行数:23,代码来源:SessionFactory.java


注:本文中的com.jcraft.jsch.Session.setConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。