如何使用 libssh2 重定向程序输出?

发布于 2024-12-09 04:26:03 字数 336 浏览 0 评论 0原文

我在 Linux 环境中将 libssh2 用于 C++ 程序,到目前为止,我可以使用 libssh2_channel_exec 在远程计算机上启动程序。不过,我想将程序的输出重定向到本地计算机(即输出应通过 ssh 传输)。 我想实现以下 bash 行的相同目标:

$ ssh user@remote ls > local_file.txt

我无法指定> local_file.txtcommand 参数的一部分,因为该文件必须写入本地计算机而不是远程计算机。

那么,如何将远程程序的输出重定向到本地计算机呢?

I'm using libssh2 for a C++ program in a Linux environment and so far I'm able to start a program on a remote machine using libssh2_channel_exec. However I'd like to redirect the program's output to the local machine (i.e. the output shall travel over ssh).
I'd like to achieve the same goal of the following bash line:

$ ssh user@remote ls > local_file.txt

I cannot specify the > local_file.txt part the command parameter because the file must be written in the local machine and not in the remote one.

So, how can I redirect a remote program's output to the local machine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蘑菇王子 2024-12-16 04:26:03

您应该使用 libssh2_channel_read 函数读取远程标准输出:

http://www.libssh2.org/libssh2_channel_read.html

you should use the libssh2_channel_read function to read the remote stdout:

http://www.libssh2.org/libssh2_channel_read.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文