When trying to connect with a remote server using console, I do the following:
$ ssh [email protected]
[email protected]'s password:
I'm trying to mimic this with the following snippet:
ssh_session session;
ssh_channel channel;
(...)
session = ssh_new();
channel = ssh_channel_new(session);
if (channel == NULL) {
fprintf(stderr, "Failed to create SSH channel.\n");
ssh_disconnect(session);
ssh_free(session);
return (1);
}
else {
puts("Channel open.");
}
char buffer[1024];
int nbytes = 0;
while ((nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0)) > 0) {
fwrite(buffer, 1, nbytes, stdout);
if (strstr(buffer, "[email protected]\'s password:") != NULL) {
break;
}
}
It seems the channel is open only if I'm logged in successfully. In my case I get Failed to create SSH channel..
Is it possible to read that prompt, with or without methods provided by libssh, before logging into a server?