I'm working on a project where I need to connect to remote AIX host to pull .zip file using JSCH API.
The code working fine in development and AT environment.
But in UAT environment its not working as expected, even though both AT and UAT are point to same remote host.
I'm getting below error NoClassDefFoundError for class
org/bouncycastle/crypto/modes/SICBlockCipher.
Please find the snap of code and the exception.
We currently in UAT phase. Your help will be appriciated
JSch jsch= null;
Session session= null;
Channel channel= null;
InputStream in= null;
ChannelSftp channelSftp = null;
jsch=new JSch();
session=jsch.getSession(remoteUserId, remoteHostName, 22);
session.setPassword(remotePassword);
session.setConfig("StrictHostKeyChecking", "no");
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp)channel;
Vector<ChannelSftp.LsEntry> fileList= channelSftp.ls(remoteImageDir);
java.lang.NoClassDefFoundError: org/bouncycastle/crypto/modes/SICBlockCipher
at org.bouncycastle.jce.provider.JCEBlockCipher.engineSetMode(Source)
at javax.crypto.Cipher$a_.a(Unknown Source)
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.init(Unknown Source)
at javax.crypto.Cipher.init(Unknown Source)
at com.jcraft.jsch.jce.AES256CTR.init(AES256CTR.java:57)
at com.jcraft.jsch.Session.checkCipher(Session.java:2072)
at com.jcraft.jsch.Session.checkCiphers(Session.java:2049)
at com.jcraft.jsch.Session.send_kexinit(Session.java:592)
at com.jcraft.jsch.Session.connect(Session.java:286)
at com.jcraft.jsch.Session.connect(Session.java:162)
Related
i'm trying to make a connection via ssh from windows to a unix server
my goal to have it in my java app so i cann run command without inputting passwords on each connect
right now i'm trying to understand what i'm doing wrong with keys
I generated a key in Tectia and uploaded it to server;
I can see it in .ssh as 2798 Apr 17 10:56 authorized_keys
my connection setup looks like this
...
JSch jsch = new JSch();
jsch.setKnownHosts("~/.ssh/know_hosts");
jsch.addIdentity("~/.ssh/authorized_keys");
System.out.println("identity added ");
Session session=jsch.getSession(user, host, 22);
session.setConfig("PreferredAuthentications", "publickey");
System.out.println("session created.");
session.connect();
System.out.println("Connected");
....
and as a result of this i'm getting this error
com.jcraft.jsch.JSchException: java.io.FileNotFoundException:
C:\Users\User\ .ssh\authorized_keys (The system cannot find the path
specified)
it's looking for the key on my local computer and not connecting to the server
what am I going wrong with these keys ?
The argument to addIdentity is a local path to your private key.
Instead, you are giving it a path to a file that:
Would contain a public key;
Does not exit locally anyway.
I want to develop a java program to download a file from SFTP server to remote server. That remote server doesn't have any shared path. I have to directly download from sftp and paste in remote windows server driver (D:).
code:
int ftpPort = 22;
JSch jsch = new JSch ();
Session session = null;
Channel channel = null;
ChannelSftp c = null;
try {
session = jsch.getSession(username, hostname, ftpPort);
logger.info("*** FTP Session created. ***");
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
logger.info("*** Session connected. ***");
//Open the SFTP channel
logger.info("*** Opening FTP Channel. ***");
channel = session.openChannel("sftp");
channel.connect();
c = (ChannelSftp) channel;
//Change to the remote directory
logger.info("*** Changing to FTP remote dir: " + remoteDirectory + " ***");
c.cd(remoteDirectory);
//Send the file we generated
try {
logger.info("*** Storing file:'" + filename + "' to local directory: '"+localDirectory+"'");
I am using Jsch and ChannelSftp for connecting to SFTP server.
As of now the above code downloads the code to local path and shared path.
Any suggestion to download the files to Remote server(windows) which doesn't hav any shared path.
Thanks.
Your code would need to run on the remote server directly and download the files from SFTP to its local disk.
Another way would be to download the file on your local machine using your code and then use something like SCP to transfer the file on the remote server, if you really don't have any shared folders.
scp /path/to/your/file user#host:/remote/path
But you said, it's Windows, so you might need to set up SSH/SCP first on that machine.
I'm running on a Linux machine a Java program that uses jcraft.jsch library to connect to an external sftp server. The code looks like:
JSch jsch = new JSch();
Session session = null;
Channel channel = null;
ChannelSftp c = null;
session = jsch.getSession(ftpUserName, ftpHost, ftpPort);
session.setPassword(ftpPassword);
channel = session.openChannel("sftp");
channel.connect();
c = (ChannelSftp)channel;
fn = c.ls("/Inbox");
c.cd("/Inbox"); //-- this line throws an error
For some reason when I run the change directory command "c.cd" I get:
4: Folder not found: /drwxr-x--- 2 ftpadmin ftpadmin 0 Jan 01 1970 /Inbox
It is weird because the listing (c.ls) of that folder does not throws an exception.
Furthermore, if I lftp from the command line from the same Linux server I can cd without any problems.
The stacktrace points to a _stat method inside the cd method.
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2108)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:1676)
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:290)
at BW_Utilities.ftp.test.testFtpJsch(test.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
The folder structure of the remote site looks like the following when I connect using Filezilla from my desktop:
I just executed the same Java code on my windows desktop machine and the cd command worked. (Windows machine runs JDK 1.6.0_29 while the Linux server runs JRE 1.6.0.27)
Does jsch relies on some other library at the OS level at the client side?
Any idea how to proceed to troubleshoot this problem?
important UPDATE
I was able to reproduce the error on my dev machine. It got to do with jsch versions being used. The linux server is using jsch-0.1.31 while the dev machine uses jsch-0.1.52. It seems that whatever is causing the error is already solved in version 0.1.52. Wooot! Wooot! Finally!
Thanks
Upgrading to jsch version 0.1.52 fixes the issue.
Try doing the following.
fn = c.ls("Inbox");
c.cd("Inbox");
I have searched a lot but couldn't get a solution for this. I need to copy a file from local windows machine to remote windows machine using java program. I have tried with JSch,
JSch jsch = new JSch();
Session session = null;
session = jsch.getSession("username","hostname",22);
session.setPassword("password");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp channel = null;
channel = (ChannelSftp)session.openChannel("sftp");
channel.connect();
File localFile = new File("filePath");
//If you want you can change the directory using the following line.
channel.cd("E:/xxx");
channel.put(new FileInputStream(localFile),localFile.getName());
channel.disconnect();
session.disconnect();
While executing the above code, i am facing the below error,
Exception in thread "main" 2: No such file
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2340)
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:342)
I have cygwin installed in remote windows machine. It seems Jsch is not able to find the windows path. The same code works properly when copying files from windows machine to linux machine.
Please tel me a solution for the above problem or is there any other options for this to achieve in java ? Thanks
In order to resolve a Windows path with a drive letter you may need to use the /cygdrive prefix. In this case, your cd method call should be called with the parameter /cygdrive/e/xxx.
I'm using JSCH to ssh to an external with Java. As of right now, my JSCH code looks like this:
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
session.setPassword(pass);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect(5000);
Channel channel = session.openChannel("shell");
channel.connect();
input.add(command);
(with input.add eventually writing my command to an OutputStream).
The code works, but the problem is that the output looks strange.
[m[?1l>(B)0[H[J[1;1H[22:40:53] [Server thread/INFO]: what[K
rather than just
[22:40:53] [Server thread/INFO]: what
If I use exec rather than shell, I'll get the latter output, however, I can't use tmux with exec because tmux needs a pseudo terminal. I've tried both exec and shell with every combination of setPty (true and false) and I still can't seem to get output that doesn't have weird symbols, works with tmux, and doesn't close the outputstream when it's not receiving anything.