0

我尝试使用在远程 linux 主机上执行 shell 命令libssh并且它有效。我按照他们教程中的示例进行操作。但是当在 Windows 远程主机上尝试时,它不起作用(我当然改变了命令)。所以我的问题是:是否可以在 Windows 主机上执行远程命令?

编辑:

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;
}

它没有工作我的意思是我没有来自服务器的响应。

4

0 回答 0