Comments (5)
Hi @ornitorenk,
channel.recv(maxBytes)
is like reading a socket and just reads whatever data was sent from the remote server, not exceeding maxBytes.
It is commonly used in a loop until you get the piece of data that you are waiting for, this is why here you only got the first chunk of data sent by your remote server.
from jumpssh.
Hi @ornitorenk,
using code example from #110 is a good start, but was just a very basic example of how to interact with a Paramiko channel.
You need to poll channel for incoming data with something like:
while True:
if not channel.recv_ready():
print("*** Channel not ready for reading.")
time.sleep(1)
continue
data_chunk = channel.recv(1024)
if len(data_chunk) == 0:
print("*** Connection terminated")
break
else:
print(f"*** Data received {data_chunk.decode('utf-8')}")
I advise you to check Paramiko channel documentation for more details on this interface.
from jumpssh.
I could not find effective solution but I have a workaround as below.
from jumpssh import SSHSession
import time
server_session = SSHSession('10.239.XXX.XXX','XXXX',password='XXXX')
switch_session = server_session.get_remote_session('10.117.XXX.XX', 'XXXX', password = 'XXXXX')
channel = switch_session.ssh_transport.open_session()
channel.get_pty()
channel.invoke_shell()
channel.send('show port\n')
count=0
while True:
if not channel.recv_ready():
count=count+1
print(count)
print("*** Channel not ready for reading.")
time.sleep(1)
if count==5 :
break
continue
data_chunk = channel.recv(1024)
if len(data_chunk)== 0:
print("*** Connection terminated")
break
else:
print(f" {data_chunk.decode('utf-8')}")
from jumpssh.
thanks @t-cas for the kind support. I've tried different bytes however it did not help:(
Actually, I've modified my code as per your feedback for the issue regarding Alcatel jumpssh. That's why, I try to use channel.send as per your recommendation.
#110 (comment)
I tried;
....
channel.invoke_shell()
output = switch_session.get_cmd_output("show software-mngt version etsi | match exact:isam\r")
print(output)
or
.....
channel.invoke_shell()
output = switch_session.run_cmd("show software-mngt version etsi | match exact:isam\r")
print(output)
Error
ChannelException: ChannelException(2, 'Connect failed')
I've faced above Error. Do you have any other recommendation to overcome from my problem?
from jumpssh.
Thanks a lot. It is working properly now. I just need to figure out "how to end the loop" in case there is no received data .
*** Channel not ready for reading.
*** Data received
Welcome to ISAM
last login : 22/08/20 23:43:37
XXX-YYY-TO02:isadmin>#show port
=================================================================
Ports on NT
=================================================================
Port Admin Link Port Cfg Oper LAG/ Port Port Port
Id State State MTU MTU Bndl Mode Encp Type
-----------------------------------------------------------------
nt:vp:1 Up Yes Up 1518 1518 - accs dotq vport
nt:mc:1 Up Yes Up 1518 1518 - accs dotq vport
.....
XXX-YYY-TO02:isadmin>#
*** Channel not ready for reading.
*** Channel not ready for reading.
*** Channel not ready for reading.
*** Channel not ready for reading.
*** Channel not ready for reading.
*** Channel not ready for reading.
Traceback (most recent call last):
File "C:\Users\agokalp\Desktop\Phyton Workshop\sshserver2server.py", line 39, in <module>
time.sleep(1)
KeyboardInterrupt
from jumpssh.
Related Issues (20)
- Could not run command in background HOT 1
- Ignore error when run command HOT 1
- The close() function does not work as expected. HOT 1
- Troublesome 'package.json' access at runtime in frozen applications HOT 3
- Question: How do I execute: ["sx su -someuser", password, somemorecommands]
- How to execute multiple commands on remote host HOT 2
- Can jumpssh supports parallel ssh connections to different hosts once the jump ssh connection is established ? HOT 1
- Jumpssh from Cisco router to another router causes ChannelException(3, 'Unknown channel type')
- problem using jumpssh dosent upload right remote path, library to ssh a server throught a gateway HOT 2
- "Error reading SSH protocol banner" occured when trying link a remote server through a jump server
- Can't execute background process on remote server HOT 1
- Add optional heartbeat param to run_cmd to check/handle disconnection during long running commands
- cannot upload file to remote server
- Problem when sending multiple commands via jumpSSH using multithreading HOT 2
- Breaks becuase of hardcoding http1.0
- Gateway session can get garbage collected while remote session is still being accessed
- how to connect through two or more getwayhost to the targethost and get the sshclient
- Add ability to select non-interactive shell
- want to ask : cannot jump to router with debug error : DEBUG:paramiko.transport:Rejecting "[email protected]" global request from server.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jumpssh.