fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

Issue while sending very big command #94

Open Jean-PhilippeD opened 10 months ago

Jean-PhilippeD commented 10 months ago

Hi,

Referencing this issue I opened : https://github.com/paramiko/paramiko/issues/2324

I tried a quick fix ofsend()command :

DEFAULT_MAX_PACKET_SIZE = 2**15

    def send(self, send_string, newline=None):
        """Saves and sends the send string provided."""
        self.current_send_string = send_string
        # send_string, _ = codecs.getdecoder(self.encoding)(send_string)
        newline = newline if newline is not None else self.newline
        # don't send till send_ready
        while not self.channel.send_ready():
            time.sleep(.009)
        if len(send_string) > DEFAULT_MAX_PACKET_SIZE:
            while len(send_string) > DEFAULT_MAX_PACKET_SIZE:
                chunck_string = send_string[:DEFAULT_MAX_PACKET_SIZE]
                self.channel.send(chunck_string)
                send_string = send_string[DEFAULT_MAX_PACKET_SIZE:]
        self.channel.send(send_string)
        self.channel.send(newline)

Here I loop over send_string until all payload is sent.

What do you think ? It seems to work in my case.

Jean-PhilippeD commented 10 months ago

Maybe using sendall is much simpler. https://github.com/paramiko/paramiko/blob/main/paramiko/channel.py#L825

fruch commented 10 months ago

Maybe using sendall is much simpler. https://github.com/paramiko/paramiko/blob/main/paramiko/channel.py#L825

send a PR with such a change, and if all tests would be pass, we'll merge and release a new version