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?

有帮助吗?

解决方案

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top