jsch

How to run multiple Unix commands in one shot

痴心易碎 提交于 2019-11-26 22:26:13
问题 I am trying to execute multiple commands in one shot but to my surprise only the first command is getting executed and the rest are skipped. And the command is cleartool setview view1234 ; cleartool setactivity activity456 ; cd /vobs/app/src/epw/WEB-INF/scripts ; pwd And the output of the above command is You can now run 'clearquest' to start Rational ClearQuest. But instead I'm expecting to see the following 3 lines of output: You can now run 'clearquest' to start Rational ClearQuest. Set

How do I run SSH commands on remote system using Java?

自古美人都是妖i 提交于 2019-11-26 22:06:14
I am new to this kind of Java application and looking for some sample code on how to connect to a remote server using SSH , execute commands, and get output back using Java as programming language. Have a look at Runtime.exec() Javadoc Process p = Runtime.getRuntime().exec("ssh myhost"); PrintStream out = new PrintStream(p.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); out.println("ls -l /home/me"); while (in.ready()) { String s = in.readLine(); System.out.println(s); } out.println("exit"); p.waitFor(); mehdi ali soltani JSch is a pure

Skipping Kerberos authentication prompts with JSch [duplicate]

孤人 提交于 2019-11-26 20:56:29
This question already has an answer here: SFTP connection through Java asking for weird authentication 2 answers I am using the Connect() method in the Ssh Java class below in order to connect to a server using SSH (JSch) and running a command in the server. The problem is that when running Connect() the server prompts the next messages: Kerberos username [********]: Kerberos password for ********: And in order to continue running I need to manually press the Enter key twice, one for the user name and one for the password. I have tried to add the next code: // Press ENTER Robot r = new Robot()

Transfer folder and subfolders using channelsftp in JSch?

纵饮孤独 提交于 2019-11-26 20:47:13
问题 I want to transfer a folder and a subfolder using channelsftp. I can successfully transfer files using channelsftp.put(src,dest) command but this does not work for folders (at least I could not make it work). So can someone please explain how can I transfer folders and subfolders using channelsftp? 回答1: To work with multilevel folder structures in jsch you: enter them; list their contents; do smth with every found item; repeat 1, 2 & 3 if subfolder is found. DOWNLOAD dirs method inside your

Using Keys with JGit to Access a Git Repository Securely

£可爱£侵袭症+ 提交于 2019-11-26 20:00:52
问题 I'm using JGit to access a remote Git repo, and I need to use SSH for it. JGit uses JSch to provide secure access. However, I'm not sure how to set the key file and the knows hosts file for JGit. What I have tried is as follows. Created a custom configuration of the SshSessionFactory, using by subclassing JSchConfigSessionFactory: public class CustomJschConfigSessionFactory extends JschConfigSessionFactory { @Override protected void configure(OpenSshConfig.Host host, Session session) {

scp via java

若如初见. 提交于 2019-11-26 19:44:38
What is the best method of performing an scp transfer via the Java programming language? It seems I may be able to perform this via JSSE, JSch or the bouncy castle java libraries. None of these solutions seem to have an easy answer. Tim Howland I ended up using Jsch - it was pretty straightforward, and seemed to scale up pretty well (I was grabbing a few thousand files every few minutes). shikhar plug: sshj is the only sane choice! See these examples to get started: download , upload . Take a look here That is the source code for Ants' SCP task. The code in the "execute" method is where the

Connect to remote MySQL database through SSH using Java

空扰寡人 提交于 2019-11-26 18:28:56
How can I connect to remote MySQL database through SSH from java application? Small code example is helpful for me and I'd appreciate this. My understanding is that you want to access a mysql server running on a remote machine and listening on let's say port 3306 through a SSH tunnel. To create such a tunnel from port 1234 on your local machine to port 3306 on a remote machine using the command line ssh client, you would type the following command from your local machine: ssh -L 1234:localhost:3306 mysql.server.remote To do the same thing from Java, you could use JSch , a Java implementation

What is the difference between the 'shell' channel and the 'exec' channel in JSch

隐身守侯 提交于 2019-11-26 18:13:23
问题 I want to be able to send many consecutive command represented as strings within a Java application to a SSH server for execution. Should I use: Channel channel = session.openChannel("shell"); -or- Channel channel = session.openChannel("exec"); 回答1: With shell channel the shell (on unix it's sh or bash or something like that, on Windows it's usually cmd.exe) is started and console is created (the same you see on the screen if you run them locally). You have a prompt which you can parse or use

Sending commands to server via JSch shell channel

南笙酒味 提交于 2019-11-26 17:38:23
问题 I can't figure it out how I can send commands via JSch shell channel. I do this, but it doesn't work: JSch shell = new JSch(); String command = "cd home/s/src"; Session session = shell.getSession(username, host, port); MyUserInfo ui = new MyUserInfo(); ui.setPassword(password); session.setUserInfo(ui); session.connect(); channel = session.openChannel("shell"); fromServer = new BufferedReader(new InputStreamReader(channel.getInputStream())); toServer = channel.getOutputStream(); channel

How do I transfer a file from one directory to another using Java SFTP Library JSch?

拟墨画扇 提交于 2019-11-26 16:59:25
问题 I need to program a file transfer using JSch library. I have a simple directory with two folders - In the SFTP_1 folder, I have a bitmap image. And the SFTP_2 folder is just an empty folder. My goal is to transfer the image using SFTP from SFTP_1 to SFTP_2 . Here is my code thus far : import com.jcraft.jsch.*; import java.awt.Desktop; import java.nio.channels.Channel; public class FileTransfer { public FileTransfer() { super(); } public static void main (String[] args) { FileTransfer