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


Java JSch.setLogger方法代码示例

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


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

示例1: build

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
public JSch build() throws JSchException {
    LOGGER.debug("Initializing JSch Logger");
    JSch.setLogger(new JschLogger());
    final JSch jsch = new JSch();
    try {
        if (null != knownHostsFileName && new File(knownHostsFileName).exists()) {
            jsch.setKnownHosts(knownHostsFileName);
        }
        if (null != privateKeyFileName && new File(privateKeyFileName).exists()) {
            jsch.addIdentity(privateKeyFileName);
        }
    } catch (JSchException e) {
        LOGGER.error("Could not access known hosts or private key file.", e);
        if (!(e.getCause() instanceof FileNotFoundException)) {
            throw new JSchException();
        }
    }
    return jsch;
}
 
开发者ID:cerner,项目名称:jwala,代码行数:20,代码来源:JschBuilder.java

示例2: listFiles

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
/**
 * Lists directory files on remote server.
 * @throws URISyntaxException 
 * @throws JSchException 
 * @throws SftpException 
 */
private void listFiles() throws URISyntaxException, JSchException, SftpException {
	
	JSch jsch = new JSch();
	JSch.setLogger(new JschLogger());
	setupSftpIdentity(jsch);

	URI uri = new URI(sftpUrl);
	Session session = jsch.getSession(sshLogin, uri.getHost(), 22);
	session.setConfig("StrictHostKeyChecking", "no");
	session.connect();
	System.out.println("Connected to SFTP server");

	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp sftpChannel = (ChannelSftp) channel;
	Vector<LsEntry> directoryEntries = sftpChannel.ls(uri.getPath());
	for (LsEntry file : directoryEntries) {
		System.out.println(String.format("File - %s", file.getFilename()));
	}
	sftpChannel.exit();
	session.disconnect();
}
 
开发者ID:szaqal,项目名称:KitchenSink,代码行数:29,代码来源:App.java

示例3: createSession

import com.jcraft.jsch.JSch; //导入方法依赖的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

示例4: SSHManager2

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
public SSHManager2(String logFile) {
	if (logFile!=null) {
		myLogger = new MyLogger(com.jcraft.jsch.Logger.DEBUG,logFile);
		JSch.setLogger(myLogger);
	}
	ssh = new JSch();
}
 
开发者ID:vagfed,项目名称:hmcScanner,代码行数:8,代码来源:SSHManager2.java

示例5: runProcess

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
@Override
public BuildFinishedStatus runProcess() {
  JSch.setLogger(new JSchBuildLogger(myLogger));
  Session session = null;
  try {
    session = myProvider.getSession();
    return executeCommand(session, myPty, myCommands);
  } catch (JSchException e) {
    myLogger.error(e.toString());
    LOG.warnAndDebugDetails(e.getMessage(), e);
    return BuildFinishedStatus.FINISHED_FAILED;
  } finally {
    if (session != null) {
      session.disconnect();
    }
  }
}
 
开发者ID:JetBrains,项目名称:teamcity-deployer-plugin,代码行数:18,代码来源:SSHExecProcessAdapter.java

示例6: Main

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
public Main(CommandLineArguments commandLineArguments) {
    if (commandLineArguments.username != null) {
        defaultUsername = commandLineArguments.username;
    }

    if (!tryLoadServerlistFile(commandLineArguments.serverListFile)) {
        System.out.println("Unable to read server list file: " + commandLineArguments.serverListFile);
        return;
    }

    if (commandLineArguments.verbose) {
        JSch.setLogger(new VerboseLogger());
    }

    SSH ssh = new SSH(commandLineArguments.privateKeyFiles, commandLineArguments.privateKeyPassphrase);

    int ok = 0;
    int errors = 0;

    for (Server server : servers) {
        if (ssh.testConnection(server)) {
            ok++;
        } else {
            errors++;
        }
    }

    String resultMessage = "Checked " + String.valueOf(ok + errors) + " servers.\n\n";
    resultMessage += "OK: " + String.valueOf(ok) + "\n";
    resultMessage += "Errors: " + String.valueOf(errors);

    System.out.println(resultMessage);
}
 
开发者ID:Programie,项目名称:SSHCheck,代码行数:34,代码来源:Main.java

示例7: registerLogger

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
protected static void registerLogger() {
	JSch.setLogger(new JSchSlf4JLogger());
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:4,代码来源:JSchHelper.java

示例8: connect

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
/**
 * Opens up a connection to specified host using the username. Connects to the source using a private key without
 * prompting for a password. This method does not support connecting to a source using a password, only by private
 * key
 * @throws gobblin.source.extractor.filebased.FileBasedHelperException
 */
@Override
public void connect()
    throws FileBasedHelperException {

  String privateKey =
      PasswordManager.getInstance(state).readPassword(state.getProp(ConfigurationKeys.SOURCE_CONN_PRIVATE_KEY));
  String knownHosts = state.getProp(ConfigurationKeys.SOURCE_CONN_KNOWN_HOSTS);

  String userName = state.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME);
  String hostName = state.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
  int port = state.getPropAsInt(ConfigurationKeys.SOURCE_CONN_PORT, ConfigurationKeys.SOURCE_CONN_DEFAULT_PORT);

  String proxyHost = state.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL);
  int proxyPort = state.getPropAsInt(ConfigurationKeys.SOURCE_CONN_USE_PROXY_PORT, -1);

  JSch.setLogger(new JSchLogger());
  JSch jsch = new JSch();

  log.info(
      "Attempting to connect to source via SFTP with" + " privateKey: " + privateKey + " knownHosts: " + knownHosts
          + " userName: " + userName + " hostName: " + hostName + " port: " + port + " proxyHost: " + proxyHost
          + " proxyPort: " + proxyPort);
  try {
    jsch.addIdentity(privateKey);
    jsch.setKnownHosts(knownHosts);

    session = jsch.getSession(userName, hostName, port);

    if (proxyHost != null && proxyPort >= 0) {
      session.setProxy(new ProxyHTTP(proxyHost, proxyPort));
    }

    UserInfo ui = new MyUserInfo();
    session.setUserInfo(ui);

    session.connect();

    log.info("Finished connecting to source");
  } catch (JSchException e) {
    if (session != null) {
      session.disconnect();
    }
    log.error(e.getMessage(), e);
    throw new FileBasedHelperException("Cannot connect to SFTP source", e);
  }
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:53,代码来源:SftpFsHelper.java

示例9: init

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
public static void init() {
    JSch.setLogger(new JSchLogger());
}
 
开发者ID:termd,项目名称:termd,代码行数:4,代码来源:JSchLogger.java

示例10: createTunnelJSch

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
private static void createTunnelJSch(String gatewayHost, String remoteHost,
                                     int remotePort, int localPort) throws Exception {
  JSch.setLogger(new MyJSchLogger());
  JSch jsch=new JSch();

  try {
    // NOTE: jsch does not support all ciphers.  User may be
    //       prompted to accept host key authenticy even if
    //       the key is in the known_hosts file.
    File knownHosts = new File(FileUtils.getHomeDir()+".ssh/known_hosts");
    if (knownHosts.exists() && knownHosts.canRead())
	    jsch.setKnownHosts(knownHosts.getAbsolutePath());
    ArrayList<File> privateKeys = new ArrayList<File>();
    if (!getSshKey().isEmpty()) {
      byte[] keyPass = null, key;
      if (!sshKeyPass.getValue().isEmpty())
        keyPass = sshKeyPass.getValue().getBytes();
      jsch.addIdentity("TigerVNC", getSshKey().getBytes(), null, keyPass);
    } else if (!getSshKeyFile().isEmpty()) {
      File f = new File(getSshKeyFile());
      if (!f.exists() || !f.canRead())
        throw new Exception("Cannot access SSH key file "+getSshKeyFile());
      privateKeys.add(f);
    }
    for (Iterator<File> i = privateKeys.iterator(); i.hasNext();) {
      File privateKey = (File)i.next();
      if (privateKey.exists() && privateKey.canRead())
        if (!sshKeyPass.getValue().isEmpty())
	        jsch.addIdentity(privateKey.getAbsolutePath(),
                           sshKeyPass.getValue());
        else
	        jsch.addIdentity(privateKey.getAbsolutePath());
    }

    String user = getSshUser();
    String label = new String("SSH Authentication");
    PasswdDialog dlg =
      new PasswdDialog(label, (user == null ? false : true), false);
    dlg.userEntry.setText(user != null ? user : "");
    File ssh_config = new File(sshConfig.getValue());
    if (ssh_config.exists() && ssh_config.canRead()) {
      ConfigRepository repo =
        OpenSSHConfig.parse(ssh_config.getAbsolutePath());
      jsch.setConfigRepository(repo);
    }
    Session session=jsch.getSession(user, gatewayHost, getSshPort());
    session.setUserInfo(dlg);
    // OpenSSHConfig doesn't recognize StrictHostKeyChecking
    if (session.getConfig("StrictHostKeyChecking") == null)
      session.setConfig("StrictHostKeyChecking", "ask");
    session.connect();
    session.setPortForwardingL(localPort, remoteHost, remotePort);
  } catch (java.lang.Exception e) {
    throw new Exception(e.getMessage()); 
  }
}
 
开发者ID:TigerVNC,项目名称:tigervnc,代码行数:57,代码来源:Tunnel.java

示例11: connect

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
/**
 * Opens up a connection to specified host using the username. Connects to the source using a private key without
 * prompting for a password. This method does not support connecting to a source using a password, only by private
 * key
 * @throws org.apache.gobblin.source.extractor.filebased.FileBasedHelperException
 */
@Override
public void connect() throws FileBasedHelperException {

  String privateKey = PasswordManager.getInstance(this.state)
      .readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_PRIVATE_KEY));
  String password = PasswordManager.getInstance(this.state)
      .readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD));
  String knownHosts = this.state.getProp(ConfigurationKeys.SOURCE_CONN_KNOWN_HOSTS);

  String userName = this.state.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME);
  String hostName = this.state.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
  int port = this.state.getPropAsInt(ConfigurationKeys.SOURCE_CONN_PORT, ConfigurationKeys.SOURCE_CONN_DEFAULT_PORT);

  String proxyHost = this.state.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL);
  int proxyPort = this.state.getPropAsInt(ConfigurationKeys.SOURCE_CONN_USE_PROXY_PORT, -1);

  JSch.setLogger(new JSchLogger());
  JSch jsch = new JSch();

  log.info("Attempting to connect to source via SFTP with" + " privateKey: " + privateKey + " knownHosts: "
      + knownHosts + " userName: " + userName + " hostName: " + hostName + " port: " + port + " proxyHost: "
      + proxyHost + " proxyPort: " + proxyPort);

  try {

    if (!Strings.isNullOrEmpty(privateKey)) {
      List<IdentityStrategy> identityStrategies = ImmutableList.of(new LocalFileIdentityStrategy(),
          new DistributedCacheIdentityStrategy(), new HDFSIdentityStrategy());

      for (IdentityStrategy identityStrategy : identityStrategies) {
        if (identityStrategy.setIdentity(privateKey, jsch)) {
          break;
        }
      }
    }

    this.session = jsch.getSession(userName, hostName, port);
    this.session.setConfig("PreferredAuthentications", "publickey,password");

    if (Strings.isNullOrEmpty(knownHosts)) {
      log.info("Known hosts path is not set, StrictHostKeyChecking will be turned off");
      this.session.setConfig("StrictHostKeyChecking", "no");
    } else {
      jsch.setKnownHosts(knownHosts);
    }

    if (!Strings.isNullOrEmpty(password)) {
      this.session.setPassword(password);
    }

    if (proxyHost != null && proxyPort >= 0) {
      this.session.setProxy(new ProxyHTTP(proxyHost, proxyPort));
    }

    UserInfo ui = new MyUserInfo();
    this.session.setUserInfo(ui);
    this.session.setDaemonThread(true);
    this.session.connect();

    log.info("Finished connecting to source");
  } catch (JSchException e) {
    if (this.session != null) {
      this.session.disconnect();
    }
    log.error(e.getMessage(), e);
    throw new FileBasedHelperException("Cannot connect to SFTP source", e);
  }
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:75,代码来源:SftpFsHelper.java

示例12: SSHSocketImplFactory

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
private SSHSocketImplFactory(String host) throws JSchException, IOException {
    JSch jsch = new JSch();
    jsch.setLogger(this);
    String passphrase = "";
    String defaultSSHDir = System.getProperty("user.home") + "/.ssh";
    String identityFile = defaultSSHDir + "/openid";
    String user = System.getProperty("user.name");
    user = System.getProperty("ssh.user", user);
    if (host == null) {
        throw new RuntimeException(
                "ssh.gateway system property must be set");
    }
    String knownHosts = defaultSSHDir + "/known_hosts";
    knownHosts = System.getProperty("ssh.knownhosts", knownHosts);
    jsch.setKnownHosts(knownHosts);
    identityFile = System.getProperty("ssh.identity", identityFile);
    jsch.addIdentity(identityFile, passphrase.getBytes());
    session = jsch.getSession(user, host);
    Properties props = new Properties();
    props.put("compression.s2c", "none");
    props.put("compression.c2s", "none");
    props.put("cipher.s2c", "blowfish-cbc,3des-cbc");
    props.put("cipher.c2s", "blowfish-cbc,3des-cbc");
    if (jsch.getHostKeyRepository().getHostKey(host, null) == null) {
        // We don't have a way to prompt, so if it isn't there we want
        // it automatically added.
        props.put("StrictHostKeyChecking", "no");
    }
    session.setConfig(props);
    session.setDaemonThread(true);

    // We have to make sure that SSH uses it's own socket factory so
    // that we don't get recursion
    SocketFactory sfactory = new SSHSocketFactory();
    session.setSocketFactory(sfactory);
    UserInfo userinfo = null;
    session.setUserInfo(userinfo);
    session.connect();
    if (!session.isConnected()) {
        throw new IOException("Session not connected");
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:43,代码来源:SSHSocketImplFactory.java

示例13: init

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
/**
 * Initializes SSH manager by configuring encryption algorithms and setting
 * SSH logger.
 */
private void init() {
	JSch.setLogger(new DefaultSSHLogger());
	SSHChannel = new JSch();
	config = new Properties();
	config.put("kex",
			"diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256");
	config.put("StrictHostKeyChecking", "no");
}
 
开发者ID:Pardus-LiderAhenk,项目名称:lider-ahenk-installer,代码行数:13,代码来源:SSHManager.java

示例14: build

import com.jcraft.jsch.JSch; //导入方法依赖的package包/类
public PublicKeySshSession build() {
	validate();

	if (logger != null) {
		JSch.setLogger(new JschLogger());
	}

	JSch jsch = new JSch();

	Session session = null;

	try {

		jsch.addIdentity(privateKeyPath.toString());

		session = jsch.getSession(username, host, port);
		session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password");

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

		session.setConfig(config);

	} catch (JSchException e) {
		throw new RuntimeException("Failed to create Jsch Session object.", e);
	}
	
	this.jschSession = session;

	return new PublicKeySshSession(this);
}
 
开发者ID:svlada,项目名称:ssh-public-key-authentication,代码行数:32,代码来源:PublicKeySshSession.java


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