gpt4 book ai didi

c - 使用 C 在本地存储远程文件

转载 作者:行者123 更新时间:2023-11-30 17:22:41 25 4
gpt4 key购买 nike

我们目前有用 C 编写的代码,我必须在其中添加逻辑来获取文件中特定内容的证据的概念证明。所以我想要完成的是:

1 - 将此文件 (/etc/vpnc/test.conf) 从远程计算机下载到临时文件(本地)

2 - 寻找一些多汁的东西来展示,证明布丁里有证据。前任。/etc/vpnc/test.conf

IPSec ID TestID
IPSec gateway blah.blah.com
IPSec secret 123456
Xauth username blah_user
Xauth password 123456!
IKE Authmode psk
#IKE DH Group dh2
#NAT Traversal Mode cisco-udp
Local Port 10000
DPD idle timeout (our side) 0

3 - 最后,只需使用已经存在的自定义函数将我的发现打印到 stdout.ex:

Xauth username blah_user 

其他人建议使用 tmpnam 和/或 mkstemp 函数

 #include <stdio.h>

int main() {
char buf[4096];
char *n=tmpnam(NULL); // Use this as the file name, not tmp_file.

// get the file
...

FILE *fp=fopen(n, "r");
unlink(n);
// Read a line into 'buf' until we run out of lines
while(fgets(buf, 4096, fp))
{
// Check the contents of 'buf' for what you want
}
}

但是我对 C 的缺乏让我放慢了速度。那么看看上面的代码,我如何得到以下结果:代码:

 rsync rsync://192.168.3.1/vpnc/test.conf

进入“n”临时文件?请原谅我的愚蠢。我保证我会拿一本 C 书来停止在论坛上唠叨

最佳答案

这是一种方法:

char cmd[200];
sprintf(cmd,"rsync rsync://192.168.3.1/vpnc/test.conf %s",n);
system(cmd);
FILE *fp=fopen(n, "r");

我假设 tmpnam 将返回一个足够短的文件名,不包含特殊字符。通常这些名称只有 10 个字符左右,因此它应该很容易与命令的其余部分一起放入 char cmd[200] 中。

关于c - 使用 C 在本地存储远程文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27929794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com