本文整理匯總了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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
}
}
示例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);
}
示例7: registerLogger
import com.jcraft.jsch.JSch; //導入方法依賴的package包/類
protected static void registerLogger() {
JSch.setLogger(new JSchSlf4JLogger());
}
示例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);
}
}
示例9: init
import com.jcraft.jsch.JSch; //導入方法依賴的package包/類
public static void init() {
JSch.setLogger(new JSchLogger());
}
示例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());
}
}
示例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);
}
}
示例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");
}
}
示例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");
}
示例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);
}