Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C中的系统调用向SCP命令发送输入 #包括 #包括 int main() { int-euid=geteuid(); setreuid(euid,euid); 系统(“echo hi”); 系统(“cp测试_文件~/dump.txt”); 系统(“scp~/dump.txthost@ipaddress:~"); 返回0;_C_Scp - Fatal编程技术网

从C中的系统调用向SCP命令发送输入 #包括 #包括 int main() { int-euid=geteuid(); setreuid(euid,euid); 系统(“echo hi”); 系统(“cp测试_文件~/dump.txt”); 系统(“scp~/dump.txthost@ipaddress:~"); 返回0;

从C中的系统调用向SCP命令发送输入 #包括 #包括 int main() { int-euid=geteuid(); setreuid(euid,euid); 系统(“echo hi”); 系统(“cp测试_文件~/dump.txt”); 系统(“scp~/dump.txthost@ipaddress:~"); 返回0;,c,scp,C,Scp,} 上面的代码是我编写的一个简短程序,它将文件复制到转储文件,然后使用终端scp命令将其发送给某人。第一次使用scp时,终端上会出现一个提示,询问用户是否要将密钥添加到主机名列表或类似的内容。然后它将提示输入密码。如何从该程序发送输入,以便密码提示接收?那代码是什么样子的 编辑:我面临的问题是,当系统调用scp时,程序会暂停,直到整个scp命令执行为止,因此在执行过程中,输入不再来自程序,而是来自用户。我不知道如何从我的程序中输入scp的密码。使用: #include <stdlib.h&

}

上面的代码是我编写的一个简短程序,它将文件复制到转储文件,然后使用终端scp命令将其发送给某人。第一次使用scp时,终端上会出现一个提示,询问用户是否要将密钥添加到主机名列表或类似的内容。然后它将提示输入密码。如何从该程序发送输入,以便密码提示接收?那代码是什么样子的

编辑:我面临的问题是,当系统调用scp时,程序会暂停,直到整个scp命令执行为止,因此在执行过程中,输入不再来自程序,而是来自用户。我不知道如何从我的程序中输入scp的密码。

使用:

#include <stdlib.h>
#include <unistd.h>

int main()
{
    int euid = geteuid();
    setreuid(euid, euid);
    system("echo hi");
    system("cp test_file ~/dump.txt");
    system("scp ~/dump.txt host@ipaddress:~");
    return 0;

此选项将自动向已知的\u hosts文件添加新密钥,而无需提示。

可能还有其他方法,但如果需要,请参阅“是”命令,或者您可以创建一个包含所需内容的文件并重定向输入检查serverfault上的以下页面,这可能有助于在其中获取密码:
system("scp -o StrictHostKeyChecking=no ~/dump.txt host@ipaddress:~");