Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Help communicating with a device

Aperta
#286 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
networking

Direzione di ricerca

Inizia esaminando le chiamate a channel.exec(), channel.write(), channel.write_all(), flush(), read_to_string() e wait_close() mostrate nell’issue, quindi confronta il loro comportamento con l’esempio funzionante in Python Paramiko che usa invoke_shell. L’issue non indica file o test del repository; per completare il lavoro sarebbe necessario stabilire il modo corretto per consentire a ssh2-rs di comunicare con l’appliance di rete e documentare o correggere il comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

question

I reached out on the beginners channel on Discord, but I haven't been able to get help there, so I thought maybe I could open an issue on here. First, I want to say that I tested against a unix device, and this worked as shown in the example; the issue I'm having is with a network appliance. I first tried using the channel.exec() function, but this gave me an exit code of 127, and the trace logs showed sh: show: command not found. The command I'm trying to send is show version, so I started thinking that this function was doing more than just sending messages back and forth across the channel. I thought that perhaps the channel.write() or channel.write_all() would be better suited for my purposes. However, when using these functions, the channel hangs as though it is never done writing, and I'm not sure how to get it to end. I would appreciate any help you can provide.

using exec:

fn main() {
    let tcp = TcpStream::connect(ip).unwrap();
    let mut sess = Session::new().unwrap();
    sess.trace(TraceFlags::all());
    sess.set_tcp_stream(tcp);
    sess.handshake().unwrap();
    sess.userauth_password(username, password).unwrap();
    assert!(sess.authenticated());
    let mut channel = sess.channel_session().unwrap();
    channel.exec("show version").unwrap();
    let mut s = String::new();
    channel.read_to_string(&mut s).unwrap();
    println!("{}", s);
    channel.wait_close().unwrap();
   println!("{}", s);```
}

using write[_all]:

fn main() {
    let tcp = TcpStream::connect("").unwrap();
    let mut sess = Session::new().unwrap();
    sess.set_tcp_stream(tcp);
    sess.handshake().unwrap();
    sess.userauth_password("", "").unwrap();
    assert!(sess.authenticated());
    let mut channel = sess.channel_session().unwrap();
    channel.write(b"show version\n").unwrap();
    // nothing below here is executed and program hangs
    println!("{}", "called write_all");
    channel.flush().unwrap();
    let mut s = String::new();
    channel.read_to_string(&mut s).unwrap();
    println!("{}", s);
    channel.wait_close().unwrap();
}

An example that works using python:

import time

from paramiko import SSHClient, AutoAddPolicy


RECIEVE_BYTES = 4096


def read_from_channel(channel):
    response = []
    time.sleep(.2)
    while channel.recv_ready():
        data = channel.recv(RECIEVE_BYTES)
        response.append(data.decode())
        time.sleep(.2)
    return "".join(response)

client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect("", username="", password="")
channel = client.invoke_shell()
# clear channel
read_from_channel(channel)
channel.sendall("show version\n")
version_data = read_from_channel(channel)
channel.close()
client.close()

print(version_data)
Lingua principale
Rust
Stelle
571
Fork
166
Merge medio
1g 18h
PR unite (30g)
5

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/ssh2-rs

Tutte le issue di rust-lang/ssh2-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.