jsch.setKnownHosts(new FileInputStream(SSHHostKey));
jsch.addIdentity(SSHKey);
session = jsch.getSession(user, host, port);
if (hostKey == null)
{
session.setConfig("StrictHostKeyChecking", "no");
}
session.setPassword(pass);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
sftp = (ChannelSftp) channel;
still I get the same exception.
Can anybody tell me how to get/retrive HostKey? I am using Windows.
Related
How do you resolve this JMSException? Thanks!
Broker: localhost - Client: FS_Proceduer already connected
javax.jms.InvalidClientIDException: Broker: localhost - Client: FS_Proceduer already connected from /127.0.0.1:56556
This is triggered by this method:
private void connectAndInitActiveMQ() throws JMSException{
logger.debug("It's ready to connect to jms service");
if(null != connection){
try{
logger.debug("Closing connection");
connection.close();
}catch(Exception e){
logger.error(e.getMessage(), e);
}
}
logger.debug("Creating a new connection");
logger.debug("Is queueConnectionFactory null? "+(queueConnectionFactory==null));
connection = queueConnectionFactory.createConnection();
logger.debug("Is the new connection null? "+(connection==null));
logger.debug("Starting the new connection");
connection.start();
logger.debug("Connected successfully: " + connection);
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
queue = session.createQueue(queueName);
messageProducer = session.createProducer(queue);
}
Is it the factory problem? Or some other source?
You would get this error if you configured your connections to have the same client ID. The JMS spec is explicit that only a single connection can connect to the remote with the same Client ID at any given time, resolve your configuration and things should work just fine.
I have a sftp server which i can connect manually using the command below
sftp -oport=4022 user#xxxxxx.com
but I am finding difficulty in doing the same with apache commons vfs.
Below is the method I am using to establish connection to the sftp server. But it not working and fails with the error "org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at xxxxxx.com"
public boolean connect(String host, String login, String password,
int port) throws Exception {
//If the client is already connected, disconnect
if (command != null) {
disconnect();
}
FileSystemOptions fso = new FileSystemOptions();
try {
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso,
"no");
session =
SftpClientFactory.createConnection(host, port, login.toCharArray(),
password.toCharArray(),
fso);
System.out.println("pass");
Channel channel = session.openChannel("ssh");
channel.connect();
command = (ChannelSftp)channel;
} catch (FileSystemException e) {
throw e;
// return false;
}
return command.isConnected();
}
Please help me with this
I am getting an error while opening connection to the broker service with VM protocol.
BrokerService broker = new BrokerService();
try {
broker.setPersistent(true);
broker.setUseJmx(false);
broker.setBrokerName("broker1");
broker.start();
while(true){
}
} catch (Exception e) {
e.printStackTrace();
}
And here is my producer;
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker1?create=false");
Connection connection = null;
Session session = null;
try {
connection = connectionFactory.createConnection();
connection.start();
I am getting this error;
javax.jms.JMSException: Could not create Transport. Reason: java.io.IOException: Broker named 'broker1' does not exist.
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:254)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:267)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:239)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:185)
at Client.main(Client.java:22)
Tim you are right, connection was not created within the same jvm.I have realized my mistake
Trying to connect to a host using ssh key auth. Below is my code:
package com.mkyong.common;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
/**
*
*/
public class UserAuthPubKey {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
try {
JSch jsch = new JSch();
String user = "XXXXXXXX";
String host = "XXXXXXXX.XXXXXXX.com";
int port = 22;
String privateKey = "~/.ssh/WF_OPENSSH.ppk";
String passphrase = "XXXXXXXXXXX";
jsch.addIdentity(privateKey,passphrase);
System.out.println("identity added ");
Session session = jsch.getSession(user, host, port);
System.out.println("session created.");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
System.out.println("session connected.....");
Channel channel = session.openChannel("sftp");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect();
System.out.println("shell channel connected....");
ChannelSftp c = (ChannelSftp) channel;
// String fileName = "test.txt";
// c.put(fileName, "./in/");
// c.exit();
// System.out.println("done");
} catch (Exception e) {
System.err.println(e);
}
}
}
what change should i make here. On debugging the error seems to occur at session.connect(); statement. I am using a private key and a passphrase to connect.
String privateKey = "~/.ssh/WF_OPENSSH.ppk";
Is that a PuTTY-format keyfile? Was it generated from puttygen, the PuTTY key generation utility? Jsch only reads OpenSSH-format key files, not PuTTY-format files.
You can use puttygen to convert the key to OpenSSH format if you want to use that key. See this question.
Get the lastest version of JSch. The old version shows Auth Fail for no reason
We are getting jcraft.jsch.JSchException: verify: false while getting the ChannelSftp. Now a days it is occurring very frequently.
Below is my environment where I am getting this error.
java version "1.7.0_10" and 1.7.0_13
weblogic 11g(10.3.6.0)
jsch jar version jsch-0.1.50.jar
any suggestions on how to resolve this issue are much helpful.
Here is my block of code that I have used for getting channel
ChannelSftp sftpChannel = null;
JSch jsch = new JSch();
Properties jschConfig = new Properties();
jschConfig.setProperty("compression.s2c", "none");
jschConfig.setProperty("compression.c2s", "none");
jschConfig.setProperty("StrictHostKeyChecking", "no");
jschConfig.setProperty("PreferredAuthentications", "publickey,password");
JSch.setConfig(jschConfig);
Session session = null;
try {
jsch.removeAllIdentity();
jsch.addIdentity(privateKeyFile);
session = jsch.getSession(user, host, port);
session.connect();
} catch (JSchException e) {
throw new RuntimeException("Failed to connect to " + host, e);
}
sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();