jsch

Removing shell stuff (like prompts) from command output in JSch

夙愿已清 提交于 2019-11-28 01:42:39
I have successfully SSH'ed into a node, sent the input, and retrieved the output. After inputting a line, the line is printed to the console, followed by a blank line, and then the output prints twice. I don't want the input to print to the console after it is entered, nor the blank line, nor the output printed a second time. Below is the code I have public void runSession() { try { Channel channel = session.openChannel("shell"); channel.setInputStream(System.in, true); channel.setOutputStream(System.out, true); channel.connect(defaultChannelTimeout); while (channel.getExitStatus() == -1) {

Commands executed using JSch behaves differently than in SSH terminal (bypasses confirm prompt message of “yes/”no\")

房东的猫 提交于 2019-11-28 01:41:05
Note: I log into a device, not a computer, so I login to configuration mode (instead of non configuration mode). I am using JSch library in Java, to login with an SSH protocol. I login like this: channel = con.openChannel("shell"); channel.connect(); In some cases, when I send through the shell a command that needs su (configuration mode) permissions (change configuration), this code bypasses the prompt confirmation message of - this may prevent other users from changing configuration. While if I enter the command manually with SSH client/terminal, I have to enter yes for confirmation. Does

Jsch error - failed to send channel request

Deadly 提交于 2019-11-27 23:50:38
问题 I am trying to connect to a SFTP remote server using JSCH library version 0.1.49. Every time I run the program I receive the following error : Initializing... Connection to SFTP server is successfully com.jcraft.jsch.JSchException: Unable to connect to SFTP server.com.jcraft.jsch.JSchException: failed to send channel request at shell.MainClass.JschConnect(MainClass.java:95) at shell.MainClass.main(MainClass.java:30) line 30 is : sftpChannel.connect() from the code below : System.out.println(

JSCH - Invalid private key

假装没事ソ 提交于 2019-11-27 22:11:40
I am running JDK 1.7 & Windows 7 using netbeans 7.2 I have generated a SSH private & public key pair (SSH2-2048 bits) using putty-keygen. I do not have any password for private key. I am now trying to connect to one of the host machine using SFTP. But when I pass private key (ppk) to set Identity, code is returning invalid private key error. I used same private key in WinSCP to connect to same host & it is working fine. Kindly help me to resolve the error. Here is my code: JSch jsch = new JSch(); Session session = null; try { jsch.addIdentity("D:\\TEMP\\key.ppk"); session = jsch.getSession(

How to Set Root Directory in Apache Mina Sshd Server in Java

我的未来我决定 提交于 2019-11-27 21:45:19
问题 I use Apache Mina Sshd API to start up a local SFTP server in java.In SFTP client i use Jcraft jsch API to create my SFTP client.I successfully start up a server.The problem is that i want to write some unit test cases to check whether client can put some files into server's root directory. Currently my SFTP server doesn't have any root directory.So i would like to know that is there is any approach to set server's root directory. Eg: C:\sftp How can i set this path as my server root

Using Keys with JGit to Access a Git Repository Securely

不羁的心 提交于 2019-11-27 19:52:18
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) { session.setConfig("StrictHostKeyChecking", "yes"); } } In the class which I access the remote Git repo, did

“Invalid privatekey” when using JSch

别等时光非礼了梦想. 提交于 2019-11-27 19:51:39
I'm using the following code to work with Git in a Java application. I have a valid key (use it all the time), and this specific code has work for me before with the same key and git repository, but now I get the following exception: invalid privatekey: [B@59c40796. At this line: jSch.addIdentity("<key_path>/private_key.pem"); My full code: String remoteURL = "ssh://git@<git_repository>"; TransportConfigCallback transportConfigCallback = new SshTransportConfigCallback(); File gitFolder = new File(workingDirectory); if (gitFolder.exists()) FileUtils.delete(gitFolder, FileUtils.RECURSIVE); Git

JSch: UnknownHostKey exception even when the hostkey fingerprint is present in the known_hosts file

谁说胖子不能爱 提交于 2019-11-27 19:22:24
问题 There are two questions about this exception already: JSchException: UnknownHostKey and com.jcraft.jsch.JSchException: UnknownHostKey I am using a Windows machine and trying to connect to a VM created with Vagrant running Ubuntu. Here is my code: public static void main(String[] args) { String host = "localhost"; String username = "vagrant"; int port = 2200; String privateKey = "C:\\keys\\openSSH_pair1\\open_ssh_private"; JSch js = new JSch(); try { js.addIdentity(privateKey, "pass"); js

Multiple commands through JSch shell

时光毁灭记忆、已成空白 提交于 2019-11-27 18:03:15
I was trying to execute multiple commands through SSH protocol using the JSch library. But I seem to have stuck and cannot find any solution. The setCommand() method can only execute single commands per session. But I want to execute the commands sequentially just like the connectbot app on the Android platform. So far my code is: package com.example.ssh; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget

Using JSch, is there a way to tell if a remote file exists without doing an ls?

徘徊边缘 提交于 2019-11-27 17:42:31
问题 Using JSch, is there a way to tell if a remote file exists without doing an ls and looping through the files to find a name match? Thanks 回答1: (This is if you're using the SFTP part of the library, an assumption I made without thinking about it.) I thought its ls(String path) would accept filenames; I can't check at the moment. If it doesn't, you don't need to iterate manually; you can use the selector variant: ls(String path, ChannelSftp.LsEntrySelector selector) 回答2: This is how I check