Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

跳板机连接远端服务器,使用rz命令卡死在传输窗口 #2597

Open
huangzhif opened this Issue Apr 15, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@huangzhif
Copy link

commented Apr 15, 2019

[简述你的问题]
如题:

使用版本

[请提供你使用的Jumpserver版本 1.x.x 注: 0.3.x不再提供支持]
python3.6.4

问题复现步骤

堡垒机连接服务器,使用rz(或sz),选择文件 确定,就一直卡在传输窗口,ctrl+c 后文件没有传到服务器

具体表现[截图可能会更好些,最好能截全]

文件大小,传输速率都显示 0.

其他

代码如下:

#!/usr/bin/env python
# -*-coding=utf-8-*-
# Auther:ccorz Mail:ccniubi@163.com Blog:http://www.cnblogs.com/ccorz/
# GitHub:https://github.com/ccorzorz

import paramiko
import sys
import os
import socket
import select
import getpass
import termios
import fcntl,struct,signal
import tty
from paramiko.py3compat import u

def ioctl_GWINSZ(fd):
    try:
        cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,'aaaa'))
    except:
        return
    return cr

def getTerminalSize():
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    return int(cr[1]), int(cr[0])

def resize_pty(signum=0, frame=0):
    width, height = getTerminalSize()
    if now_channel is not None:
        now_channel.resize_pty(width=width, height=height)

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('IP',port=22,username='root',password='PWD',allow_agent=False,look_for_keys=False)

chan = client.invoke_shell()

global now_channel
now_channel = chan
resize_pty()
signal.signal(signal.SIGWINCH,resize_pty)

stdin = os.fdopen(sys.stdin.fileno(),'rb',0)

fd = stdin.fileno()

oldtty = termios.tcgetattr(fd)
newtty = termios.tcgetattr(fd)
newtty[3] = newtty[3] | termios.ICANON

try:
    tty.setraw(fd)
    tty.setcbreak(fd)
    chan.settimeout(0.0)

    while True:
        try:
            r, w, e = select.select([chan, sys.stdin], [], [])
        except:
            continue
        # flag = fcntl.fcntl(sys.stdin,fcntl.F_GETFL,0)
        # fcntl.fcntl(sys.stdin.fileno(),fcntl.F_SETFL,flag|os.O_NONBLOCK)
        if chan in r:
            try:
                x = chan.recv(10240).decode('utf-8', errors='ignore')
                if len(x) == 0:
                    print('\r\n*** EOF\r\n')
                    break
                sys.stdout.write(x)
                sys.stdout.flush()
            except socket.timeout:
                pass
        if sys.stdin in r:
            x = sys.stdin.read(1)
            # x = os.read(sys.stdin.fileno(),4096)
            # x = u(stdin.read(3))
            if len(x) == 0:
                break
            chan.send(x)

finally:
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)


chan.close()
client.close()

[注:] 完成后请关闭 issue
图片
Snipaste_2019-04-15_11-30-30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.