hierynomus / hierynomus/sshj

No data from the InputStream

Open
#251 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.7k
Forks
620
Avg merge
3d 23h
Merged PRs (30d)
11

Description

Hi,
I am completely new to this API, I'm using this API to get the target device(Cisco IOS) configuration with few commands like **show running-config.**.
Here I'm facing one challenge while using this API on a few devices,

**Scenario**: I'm connecting to a device through sshj to retrieve the device configuration by executing commands on the target host, able to connect to the device and executing commands properly but facing one challenge here, I'm unable to retrieve whole configuration from the target device, it is only giving half of the data from the target host then there is no data in Input stream, please help me out from this

Code snippet :
public class Exec {

public static void main(String... args) throws Exception {
final SSHClient ssh = new SSHClient();
try {
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.loadKnownHosts();
} catch (Exception e) {

}
ssh.connect("XX.XX.XX.XX", 22);
try {
ssh.authPassword("username", "password");
Session session = ssh.startSession();
InputStream inputstream = session.getInputStream();
OutputStream outputstream = session.getOutputStream();
session.allocateDefaultPTY(); // Tried with other PTY method like vt102,exterm..
session.startShell();
new Thread() {
public synchronized void run() {
try {
int len = 0;
while (len != -1) {
byte[] buf = new byte[1024 \* 10];
len = inputstream.read(buf, 0, buf.length);
System.out.println( new String(buf, 0, 1024 \* 10));
}
}catch(Exception e){
e.getMessage();
}
}
}.start();
try {
outputstream.write(("show running-config" + "\n").getBytes());
outputstream.flush();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
}
}

Note : we have tried with VT100,VT102 and xterm PTY types and also we have suspected issue with sleep time initially then increased sleep time but no luck. please help me out
Thanks,
RamaKrishna.

Contributor guide

No contributing guide indexed for this repository

Research direction

The only concrete entry point is the Java Exec example, especially the session shell, InputStream read loop, and session lifecycle. Start by reviewing how these SSHJ APIs are used together and determine whether the reported partial output can be reproduced; done is a confirmed cause and a clearly scoped change or documentation update.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.