How to send EOF to stdin in paramiko?

I would like to execute some program via ssh and redirect its input from a file. The behavior of the following code:

channel.exec_command('cat') with open('mumu', 'r') as f: text = f.read() nbytes = 0 while nbytes < len(text): sent = channel.send(text[nbytes:]) if sent == 0: break nbytes += sent 

should be equivalent (subject to public key authentication):

  ssh user@host cat < mumu 

However, the application freezes, expecting more input. I think this is because the stdin thread never closes. How to do it?

+4
source share
2 answers

Call shutdown() (or shutdown_write() ) on the channel.

+5
source

Call the method: channel.shutdown_write() .

+4
source

Source: https://habr.com/ru/post/1305674/


All Articles