[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Not able to send several commands to the server


Hello Development team, currently Im trying to stablish a connection to my
beaglebone black(Texas Instruments Dev Board) using libssh library and
managed to authenticate and login as root but Im not able to send multiple
commands to my remote server(beaglebone black). Also if I try to send a
different command rather than "ls -l" "echo XXX" seems it is throwing an
error like this:

module.js:340
    throw err;
          ^
Error: Cannot find module 'bonescript'
    at Function.Module._resolveFilename (m
    at Function.Module._load (module.js:28
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/home/root/RsBo
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (modu
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:31
    at Module.runMain (module.js:492:10)


Running the same command using Putty works and my node script is executed...

Can you please help me with this?

Below I will paste my code:


#include "stdafx.h"
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <io.h>



#if defined(_WIN32) || defined(_WIN64)
  #define snprintf _snprintf
  #define vsnprintf _vsnprintf
  #define strcasecmp _stricmp
  #define strncasecmp _strnicmp
#endif

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
  ssh_session my_ssh_session;
ssh_channel channel;

int open_ssh_channel(ssh_session session);
int close_ssh_Channel();


int main()
{

  int rc;
  int port = 22;
  my_ssh_session = ssh_new();
  char buffer[256] = "node blinkled.js";
  int nbytes=0, nwritten;




  if (my_ssh_session == NULL)
    exit(-1);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "192.168.7.2");
   ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
   ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "root");
  rc = ssh_connect(my_ssh_session);
  if (rc != SSH_OK)
  {
    fprintf(stderr, "Error connecting to localhost: %s\n",
            ssh_get_error(my_ssh_session));
    exit(-1);
  }
  else
  printf("Conected to host BBB\n");


  rc = ssh_userauth_password(my_ssh_session, NULL, "password");
  if (rc != SSH_AUTH_SUCCESS)
  {
    fprintf(stderr, "Error authenticating with password: %s\n",
            ssh_get_error(my_ssh_session));
    ssh_disconnect(my_ssh_session);
    ssh_free(my_ssh_session);
    exit(-1);
  }


  open_ssh_channel(my_ssh_session);
/*       rc = ssh_channel_request_shell(channel);
  if (rc != SSH_OK) return rc;*/



 rc = channel_request_exec(channel, "ls -l");
   if (rc > 0) {
     return -1;
   }

 rc = channel_request_exec(channel, "node RsBox.js");
   if (rc > 0) {
     return -1;
   }



   while ((rc = channel_read(channel, buffer, sizeof(buffer), 1)) > 0) {
     if (fwrite(buffer, 1, rc, stdout) != (unsigned int) rc) {
       return -1;
     }
 nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
   }




    printf("Press ENTER to exit program");
  getchar();

  //ssh_disconnect(my_ssh_session);
  //ssh_free(my_ssh_session);
}




int open_ssh_channel(ssh_session session)
{

  int rc;
 // char buffer[256];
 // unsigned int nbytes;

  channel = ssh_channel_new(session);
  if (channel == NULL) return SSH_ERROR;
  rc = ssh_channel_open_session(channel);
  if (rc != SSH_OK)
  {
    ssh_channel_free(channel);
    return rc;
  }



}


Thank you in advance for your help!


Un cordial saludo.

Moises Cedeño Torres



-- 
Un cordial saludo.

Moises Cedeño Torres

Follow-Ups:
Re: Fwd: Not able to send several commands to the serverAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org