如何使用C中的OpenSSH库执行任意命令
我是初学者C程序员,我得到了一个旧的项目,请使用OpenSSH库( https://github.com/ openssh/openssh-portable ),其中我需要通过SSH连接并在设备上执行一组命令。我能够验证:
if ((res = sshpkt_start(ssh, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
(res = sshpkt_put_cstring(ssh, login)) != 0 ||
(res = sshpkt_put_cstring(ssh, service)) != 0 ||
(res = sshpkt_put_cstring(ssh, ssh_method_name)) != 0 ||
(res = sshpkt_put_u8(ssh, 0)) != 0 ||
(res = sshpkt_put_cstring(ssh, password)) != 0 ||
(res = sshpkt_add_padding(ssh, 64)) != 0 ||
(res = sshpkt_send(ssh)) != 0)
但是出现了问题,如何执行所需的命令?我尝试了这样的事情,但它不起作用:
if ((res = sshpkt_start(ssh, SSH2_MSG_SERVICE_REQUEST)) != 0 ||
(res = sshpkt_put_cstring(ssh, "mkdir test123")) != 0 ||
(res = sshpkt_send(ssh)) != 0)
{
您能告诉我如何正确运行命令吗?
I am a beginner C programmer, I got an old project use openssh library(https://github.com/openssh/openssh-portable) in which I need to connect via SSH and execute a set of commands on the device. I was able to auth:
if ((res = sshpkt_start(ssh, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
(res = sshpkt_put_cstring(ssh, login)) != 0 ||
(res = sshpkt_put_cstring(ssh, service)) != 0 ||
(res = sshpkt_put_cstring(ssh, ssh_method_name)) != 0 ||
(res = sshpkt_put_u8(ssh, 0)) != 0 ||
(res = sshpkt_put_cstring(ssh, password)) != 0 ||
(res = sshpkt_add_padding(ssh, 64)) != 0 ||
(res = sshpkt_send(ssh)) != 0)
But the question arose, how do I execute the commands I need? I tried something like this, but it doesn't work:
if ((res = sshpkt_start(ssh, SSH2_MSG_SERVICE_REQUEST)) != 0 ||
(res = sshpkt_put_cstring(ssh, "mkdir test123")) != 0 ||
(res = sshpkt_send(ssh)) != 0)
{
Can you please tell me how to run the command correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论