views:

214

answers:

2

I would like to execute some program through ssh and redirect its input from a file. The behaviour 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 to (assuming public-key authentication):

 ssh user@host cat < mumu

However the application hangs waiting for more input. I think this happens because the stdin stream is never closed. How do I do that?

+2  A: 

CloseShutdown the channel.

Roger Pate
what happens to stdout and stderr then?
Alexandru
@Alexandru: I had the wrong function.
Roger Pate
A: 

call the method: channel.shutdown_write()

Tim