我是一个初级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)
{
你能告诉我如何正确运行这个命令吗?