Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Linux 环境中将 libssh2 用于 C++ 程序,到目前为止,我可以使用libssh2_channel_exec. 但是,我想将程序的输出重定向到本地机器(即输出将通过 ssh 传输)。我想实现以下 bash 行的相同目标:
libssh2_channel_exec
$ ssh user@remote ls > local_file.txt
我无法指定参数的> local_file.txt部分,command因为文件必须写入本地机器而不是远程机器。
> local_file.txt
command
那么,如何将远程程序的输出重定向到本地机器呢?
您应该使用 libssh2_channel_read 函数来读取远程标准输出:
http://www.libssh2.org/libssh2_channel_read.html