I successfully open an ssh connection with paramiko.
As i have want to use pexpect for automatic interaction with the system on the remote end, I would like to to pass the paramiko connection to pexpect.fdpexpect.fdspawn, but the two don't fit together.
Paramiko gives me a file descriptor, but the documentation is explicit about the fact that it cannot be used for reading or writing. What I need is a bidirectional file-descriptor for reading and writing, but I have a hard time figuring out how to connect the dots.
I understand why this piece of code doesn't work, but I don't know how to create something that does work.
#!/usr/bin/env python3
import pexpect
import pexpect.fdpexpect
import paramiko
sshc = paramiko.client.SSHClient()
sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sshc.connect('192.0.2.1', username='redacted', password='redacted',
look_for_keys=False, allow_agent=False)
io = pexpect.fdpexpect.fdspawn(sshc.invoke_shell().fileno())
io.sendline('')