Page MenuHomePhabricator

Error Message : channel request exec failed.
Open, Needs TriagePublic

Description

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.
{F458445}

Event Timeline

Lakkan updated the task description. (Show Details)
Lakkan updated the task description. (Show Details)
Lakkan updated the task description. (Show Details)
This comment was removed by Lakkan.
Lakkan added a project: Restricted Project.Aug 4 2020, 7:18 PM

Error message is shown in the picture below.

Do you see some errors in the server logs?

Lakkan renamed this task from ssh_channel_request_exec is failed. to Error Message : channel request exec failed..Aug 5 2020, 10:58 AM
Lakkan updated the task description. (Show Details)
Lakkan updated the task description. (Show Details)

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.