execute command on remote windows machine using libssh

761 Views Asked by At

I tried executing a shell command on a remote linux host using libssh and it worked. I followed the example from their tutorial . But when tried on a windows remote host, it didn't work (I changed the command of course). So my question is: is it possible to execute a remote command on a windows host?

EDIT:

int show_remote_files(ssh_session session){
ssh_channel channel;
int rc;
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;
 }
rc = ssh_channel_request_exec(channel, "dir");
if (rc != SSH_OK)
 {
ssh_channel_close(channel);
ssh_channel_free(channel);
return rc;
 }
char buffer[256];
int nbytes;
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
while (nbytes > 0)
{
  if (fwrite(buffer, 1, nbytes, stdout) != nbytes)
  {
    ssh_channel_close(channel);
    ssh_channel_free(channel);
    return SSH_ERROR;
  }
  nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
if (nbytes < 0)
{
  ssh_channel_close(channel);
  ssh_channel_free(channel);
  return SSH_ERROR;
}

And by it didn't work I meant I had no response from the server.

0

There are 0 best solutions below