如何使用 libssh2 重定向程序输出?
我在 Linux 环境中将 libssh2 用于 C++ 程序,到目前为止,我可以使用 libssh2_channel_exec
在远程计算机上启动程序。不过,我想将程序的输出重定向到本地计算机(即输出应通过 ssh 传输)。 我想实现以下 bash 行的相同目标:
$ ssh user@remote ls > local_file.txt
我无法指定> local_file.txt
是 command
参数的一部分,因为该文件必须写入本地计算机而不是远程计算机。
那么,如何将远程程序的输出重定向到本地计算机呢?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 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