Help communicating with a device
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
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/ssh2-rs
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
enhancement help wanted
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Tutte le issue di rust-lang/ssh2-rs
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
compiler P4 perf
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HerringtonDarkholme/hd-lang#1044 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted r-docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
servo/rust-smallvec#824 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
akitaonrails/ai-usagebar#552 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100