You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're connecting as a client, which SSH server are you connecting to?
OpenSSH
If you're using paramiko as part of another tool, which tool/version?
No response
What are you trying to do with paramiko?
I hope to use paramiko to make an ssh interactive client, Works like the ssh root@xx.xx.xx.xx command in linux
How are you trying to do it, and what's happening instead?
So I wrote a python code to achieve this and it works fine except when I use vim!
When I use vim to edit any file, it will leak a bunch of garbled characters in the file, looks like terminal control code, like this:
This problem occurs when I open any file using vim
Obviously I used xterm - 256color as the term type. This was not specified manually. I read it from the macos terminal environment variable $TERM.
I will show my code below so that teachers can troubleshoot this problem. Thank you very much!
I dont know what I did wrong, hope I can get help, thanks again
importthreading, os, time, paramikoimportsysimportttyimporttermiosclasssshSocket():
def__init__(self, cons):
# 连接sshprint(cons)
host=cons["host"]
port=int(cons["port"])
user=cons["user"]
authType=cons["authType"]
passwd=cons["passwd"]
privkey=cons["rsa_path"]
client=paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, port, user, passwd)
termT=os.environ.get('TERM')
self.chan=client.invoke_shell(termT)
defclose(self):
self.chan.close()
self.client.close()
defresize(self, width, height):
self.chan.resize_pty(width=width, height=height)
defread(self) ->str:
data=self.chan.recv(1024)
returndatadefsend(self, data):
# 向sshsocket发送数据self.chan.send(data.encode())
# Create ssh connectioncons= {
"host": "xxxxxxx",
"port": 22,
"user": "root",
"authType": 'password',
"passwd": "xxxxxx",
"rsa_path": ""
}
ssh_socket=sshSocket(cons)
# Dynamically resize pty windowdefsizes():
oh, ow='', ''whileTrue:
time.sleep(1)
w, h=os.get_terminal_size()
ifoh!=horow!=w:
print('大小改变')
ssh_socket.resize(w, h)
ow, oh=w, hthreading.Thread(target=sizes).start()
# Put the terminal into raw modedefget_char():
fd=sys.stdin.fileno()
old_settings=termios.tcgetattr(fd)
try:
tty.setcbreak(fd)
whileTrue:
dd=sys.stdin.read(1)
ifdd.encode() ==b'\x1b':
dd+=sys.stdin.read(2)
returnddfinally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
# Ssh standard output and standard error are sent to the terminaldefechos():
# sys.stdout.write(ssh_socket.read())# sys.stdout.flush()stdfile=open('/dev/stdout', 'wb')
whileTrue:
stdfile.write(ssh_socket.read())
stdfile.flush()
threading.Thread(target=echos).start()
# Terminal stdin sent to sshwhileTrue:
try:
char=get_char()
# if char == '\n':# char = '\r'except:
char='\x03'ssh_socket.send(char)
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Are you using paramiko as a client or server?
Client
What feature(s) aren't working right?
SSH
What version(s) of paramiko are you using?
3.3.1
What version(s) of Python are you using?
3.11.6
What operating system and version are you using?
MacOS
If you're connecting as a client, which SSH server are you connecting to?
OpenSSH
If you're using paramiko as part of another tool, which tool/version?
No response
What are you trying to do with paramiko?
I hope to use paramiko to make an ssh interactive client, Works like the ssh root@xx.xx.xx.xx command in linux
How are you trying to do it, and what's happening instead?
So I wrote a python code to achieve this and it works fine except when I use vim!
When I use vim to edit any file, it will leak a bunch of garbled characters in the file, looks like terminal control code, like this:
Obviously I used
xterm - 256color
as the term type. This was not specified manually. I read it from the macos terminal environment variable $TERM.I will show my code below so that teachers can troubleshoot this problem. Thank you very much!
I dont know what I did wrong, hope I can get help, thanks again
Anything else?
No response
The text was updated successfully, but these errors were encountered: