T241: Error Message : channel request exec failed.
Description
Originally reported by Lakkan: https://bugs.libssh.org/T241
I have written following program to connect to the remote server and then execute the ccommand remotely. specified apifunction is failed <rc = ssh_channel_request_exec(channel, "dir"); > while executing the command. I am building the program on windows-10 environment using visual studio. Below is the image which shows error message. Please let me know the reason for the failure so that I can correct it.
Below error message is shown when specified api function = rc = ssh_channel_request_exec(channel, "dir") is executed. ** channel request exec failed.**
Here is the source code that is written to execute the command remotely.
#include "stdafx.h"
#include "libssh.h"
#include "sftp.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int verbose = SSH_LOG_PROTOCOL;
int port = 22;
int rc = 0;
char *username = "testsftp";
char *passwd = "sxxxxxxxx";
ssh_session my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "96.23.69.24");
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbose);
rc = ssh_connect(my_ssh_session);
printf("conn: ok=?%d, %d, %s\n", rc==SSH_OK, rc, ssh_get_error(my_ssh_session));
rc = ssh_userauth_password(my_ssh_session, username, passwd);
printf("conn: ok=?%d, %d, %s\n", rc==SSH_OK, rc, ssh_get_error(my_ssh_session));
ssh_channel channel;
channel = ssh_channel_new(my_ssh_session);
rc = ssh_channel_open_session(channel);
printf("conn: ok=?%d, %d, %s\n", rc==SSH_OK, rc, ssh_get_error(my_ssh_session));
rc = ssh_channel_request_exec(channel, "dir");
printf("conn: ok=?%d, %d, %s\n", rc==SSH_OK, rc, ssh_get_error(my_ssh_session));
ssh_channel_close(channel);
ssh_channel_free(channel);
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
return 0;
}
...
Below you can see the picture with the error message.
(File deleted)
### Comments:
**Lakkan commented on 2020-08-04 17:18:57 UTC:**
Error message is shown in the picture below.
![image](/uploads/8076b3120ba8e2e7398c42cb6d9581b4/image.png)
----
**Jakuje commented on 2020-08-05 06:37:58 UTC:**
Do you see some errors in the server logs?
----
**Lakkan commented on 2020-08-07 05:03:27 UTC:**
Server Administrator is on vacation for a week, once he is back I will share the information from the server logs. I thank you very much for your response.
----