jsch

Not able to execute Unix commands containing variables using JSch library

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:28:21
问题 I have written a Java program which when executed would open an upload wizard through which a user can select a file. After doing this, the selected file would be transferred/uploaded to a Unix box to a directory which the user specifies and processed further. Here are the steps/actions: Browse the file through the upload wizard After this the program would prompt for a new directory to be created, the name of which the user can give as an input The program creates a new directory (source)

How to get one stream from error stream and input stream when calling a script using JSCH

笑着哭i 提交于 2019-12-13 19:43:15
问题 I am calling a script file (.sh) located on remote machine using JSCH. During execution the script outputs both error and success statements. The JSCH code what I have written exhibits two streams, InputStream & Error Stream How can I get an single input stream that contains error and output ? Channel channel=session.openChannel("exec"); ((ChannelExec)channel).setCommand("/opt/sdp/SnapShot/bin/dumpSubscribers.ksh");; InputStream in=channel.getInputStream(); InputStream error=((ChannelExec

JSch is not included in jdk 1.7?

岁酱吖の 提交于 2019-12-13 10:26:03
问题 I was trying to use JSch to connect to a mysql via ssh. According to JSch website, http://www.jcraft.com/jsch/ it should work with j2se 1.4 and up, "no additional libraries required". I have jdk 1.7 installed. Howver got the error saying "package com.jcraft.jsch does not exist, import com.jcraft.jsch.JSch;" when I compiled my java code. I wonder how to get it to work. 回答1: Add the JSch JAR in the application "lib" folder. Or update your system class path with JSch.JAR in Windows Go to Advance

Unzip file on SFTP Server

坚强是说给别人听的谎言 提交于 2019-12-13 09:57:25
问题 I have connected to my remote server via FTP and i put some zip file using following code. channelSftp.cd(SFTPWORKINGDIR + "/" + remoteDestinationDir); File file = new File(localSourceToFile); LOG.info("Transferring file: " + localSourceToFile + " to "+ SFTPWORKINGDIR + "/" + remoteDestinationDir); FileInputStream fis = new FileInputStream(file); channelSftp.put(fis, file.getName()); fis.close(); LOG.info("Transfer successful"); Now, I want to unzip file on server 回答1: It seems that

Two-step verification using JSCH library

本小妞迷上赌 提交于 2019-12-13 07:22:41
问题 I am trying to use java to connect to a Linux server which has a two-step verification login. I'm using the jsch library, this is the code I've got so far: session = jsch.getSession(username, ip); Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.setPassword(password); session.connect(); System.out.println("Connected to " + ip); Obviously when I run this script I get an "Auth failed" error as I haven't enter the

Copy all files with specific extension from remote server with Java

亡梦爱人 提交于 2019-12-13 04:39:39
问题 Hey everybody I'm trying to create a small script that will let me copy all files with a specific extension from a remote linux machine to my local machine through sftp. This is the code I have so far, which lets me copy one file from the remote machine to my local machine, using Jsch, if I give the full path. package transfer; import com.jcraft.jsch.*; import java.io.File; import java.io.FilenameFilter; import java.util.Scanner; public class CopyFromServer { public static void main(String

JSch channel.disconnect prevent logs from printing

醉酒当歌 提交于 2019-12-13 01:50:06
问题 I'm running shell script on a remote machine using JSch and printing the command logs in my log file using JSch channel. Problem is that as the script ends, I do a channel.disconnect and soon after disconnect, the System.out stop printing into the log file. Here is the code: private int runShellScript(HashMap bundleDetails) { int exitStatus = -1; Channel channel = null; Session session = null; try { java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking",

Telnet support in JSch

ぐ巨炮叔叔 提交于 2019-12-13 01:27:34
问题 I'm currently building a Java application which will connect to a switch using Telnet or SSH. I'm currently using the JSch for the SSH connection, but I read in Stack Overflow question SSH and Telnet library for java that JSch also supports Telnet. Is this correct? And if so, could some one provide a small example? 回答1: The JSch is an SSH library. Quoting the JSch web page: JSch is a pure Java implementation of SSH2 . No mention on Telnet. Also, there's no mention of the "telnet" or "23" in

Spring integration outbound channel adapters not closing the open sockets and leaving the file handles open

♀尐吖头ヾ 提交于 2019-12-12 19:15:22
问题 We are using spring integration adapters for file ftp in our project, the problem we are facing is, the adapters are not closing the open socket connections. As a result, other modules which are in the same managed server are failing with "Too many open files" socket connection exception. Is there a way to close the unused open socket connections from the channel adapters Or Can we get the underlying jsch connections and close the sockets from sftp channel adapters. We have tried caching

Not able to connect to Secured Channel when doing SFTP with JSch

好久不见. 提交于 2019-12-12 15:36:01
问题 I am trying to implement JSch to retrieve a file from remote windows sftp server to Linux. Session session = null; Channel channel = null; ChannelSftp channelSftp = null; try{ JSch jsch = new JSch(); session = jsch.getSession("userName","hostName",22); session.setPassword("password"); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); System.out.println(session.sendKeepAliveMsg()); channel =