jsch

Connecting to server via SSH using Java - JSch and issuing shell commands

岁酱吖の 提交于 2021-02-20 03:52:01
问题 I'm trying to write a program that connects via SSH to a remote Linux server using Java. I've found a number of examples online to do this using the JSch package, but they're mostly for issuing a single command to the server right after authentication. Is there any way, however, to first authenticate with the SSH server, then, over the connection, issue commands from the user input like you would via a remote shell? 回答1: If you want to implement an interactive shell, you need to use SSH

Connecting to server via SSH using Java - JSch and issuing shell commands

倖福魔咒の 提交于 2021-02-20 03:50:46
问题 I'm trying to write a program that connects via SSH to a remote Linux server using Java. I've found a number of examples online to do this using the JSch package, but they're mostly for issuing a single command to the server right after authentication. Is there any way, however, to first authenticate with the SSH server, then, over the connection, issue commands from the user input like you would via a remote shell? 回答1: If you want to implement an interactive shell, you need to use SSH

How to store multiple lines of command output to a variable using JSch

安稳与你 提交于 2021-02-19 05:30:30
问题 So, I have a nice bit of code (that I'm struggling to understand), that allows me to send a command to my server, and get one line of response. The code works, but I would like to get multiple lines back from the server. The main class is: JSch jSch = new JSch(); MyUserInfo ui = new MyUserInfo(); String Return = "Error"; try { String host = "Username@HostName"; String user = host.substring(0, host.indexOf('@')); host = host.substring(host.indexOf('@') + 1); Session rebootsession = jSch

Create a SSH private key with ssh-keygen that is accepted by JSch [duplicate]

孤人 提交于 2021-02-18 12:47:08
问题 This question already has answers here : “Invalid privatekey” when using JSch (6 answers) Closed 1 year ago . Not directly a programming question, but somehow related. JSch (Java SSH library) does not seem to allow private keys that macOS 10.14 creates using $ ssh-keygen -t rsa -b 4096 What command I should use to create a private key file with such a format: -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,.... which is accepted by JSch? 回答1: You seem to need a

Check whether the path exists on server or not in Java

岁酱吖の 提交于 2021-02-09 11:52:10
问题 I am creating a Java program in which I am uploading file to server on a particular path. I am using jSch for sftp . So, before uploading the file, I want to check if the given directory exists on server or not. if(path exists) //upload file to the location else //create the directory and then upload the file. How do I check the path exists or not? Note: I am executing the code on a client that will check for the existence of a remote directory on a server. So please don't suggest File.exists

Purpose of pubkey parameter of JSch.addIdentity

痞子三分冷 提交于 2021-02-08 06:33:15
问题 I'm referring to public void addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase) throws JSchException I tried using it and no matter what input I give as pubkey (doesn't matter the length or the characters), as long as the prvkey matches, the connection will be established. Is this the normal behavior? Why is the pubkey even requested then? After a bit more research, it seems like the pubkey is not ignored on purpose, but it has to respect certain rules to be taken into

Java - JSCH Library - Run command which expects password

一个人想着一个人 提交于 2021-02-08 05:24:25
问题 I am writing a java program which runs rsync on local Linux host to copy data to remote host. I am using jsch library. I looked at jsch examples, but I didn't find anything relevant. I can't setup key authentication, so i was expecting to automated password entry of remote host when rsync command run prompts for the password. I searched online for some ways of doing it, I don't find any easy way of doing it. Following function just executes command fed to it, this function is part of a class

Spring Data JPA with ssh tunnel to a remote MySQL server

有些话、适合烂在心里 提交于 2021-02-06 14:24:55
问题 I'm using Spring Data JPA with Hibernate as persistence provider in conjunction with a remote MySQL5 Server for a job that periodically replicates a subset of internal data. The job (i.e. a quartz-scheduled java application) runs once per dai and needs approx. 30seconds to complete the synchronization). For safety reasons we don't want to open the remote server for direct connections from outside (i.e. other than localhost). I've seen examples with Jsch to programmatically set up an ssh

Spring Data JPA with ssh tunnel to a remote MySQL server

╄→гoц情女王★ 提交于 2021-02-06 14:05:21
问题 I'm using Spring Data JPA with Hibernate as persistence provider in conjunction with a remote MySQL5 Server for a job that periodically replicates a subset of internal data. The job (i.e. a quartz-scheduled java application) runs once per dai and needs approx. 30seconds to complete the synchronization). For safety reasons we don't want to open the remote server for direct connections from outside (i.e. other than localhost). I've seen examples with Jsch to programmatically set up an ssh

Spring Data JPA with ssh tunnel to a remote MySQL server

独自空忆成欢 提交于 2021-02-06 14:04:53
问题 I'm using Spring Data JPA with Hibernate as persistence provider in conjunction with a remote MySQL5 Server for a job that periodically replicates a subset of internal data. The job (i.e. a quartz-scheduled java application) runs once per dai and needs approx. 30seconds to complete the synchronization). For safety reasons we don't want to open the remote server for direct connections from outside (i.e. other than localhost). I've seen examples with Jsch to programmatically set up an ssh