gpt4 book ai didi

对使用 libcurl 下载的文件所做的更改不会生效

转载 作者:行者123 更新时间:2023-11-30 17:50:00 24 4
gpt4 key购买 nike

让我更详细地解释一下。我正在尝试编写一个程序,从远程 FTP 服务器下载文件,在文件末尾添加一行,然后重新上传。文件操作有效,文本被附加到文件中并重新上传,但是当我再次下载文件时,没有附加文本。我编写了一个小测试程序来演示这一点;这是 Pastebin 的代码:

http://pastebin.com/r07TkxEK

程序在初始运行和后续运行中打印以下输出::

Remote URL: ftp://orangesquirrels.com
Got data.
Local data file size: 678 bytes.
Current position in file: 678
Uploading database file back to server...
Local data file size: 690 bytes.
Remote URL is ftp://orangesquirrels.com !
*** We read 690 bytes from file.

如果程序正常运行,后续运行的输出应该是:

Remote URL: ftp://orangesquirrels.com
Got data.
Local data file size: 690 bytes.
Current position in file: 690
Uploading database file back to server...
Local data file size: 702 bytes.
Remote URL is ftp://orangesquirrels.com !
*** We read 702 bytes from file.

因为数据被写入文件并重新上传(我知道这一点是因为上传的文件比下载的文件大),我认为上传有效;我怀疑问题出在下载过程和/或curl_database_write函数中。我一直在尽一切人道的努力来找出发生这种情况的原因,但无济于事。如果有人知道任何为什么这不起作用,我很想知道。我得到报酬来编写这个程序,而且我知道我必须尽快找到解决方案......

最佳答案

您没有在 download() 函数中使用“short_database”或“file_to_write”。因此,您从 ftp 服务器下载/tmp/musiclist.txt,而不是 musiclist.txt。

您应该检查您的定义,以及何时使用定义、何时使用字符串变量以及何时使用参数

#define DATABASE_FILE "/tmp/musiclist.txt"
#define REMOTE_DATABASE_FILE "musiclist.txt"

int main() {
remove(DATABASE_FILE);
download(DATABASE_FILE, "musiclist.txt", REMOTE_URL, "Testing 123");
// ^^^ should't this be REMOTE_DATABASE_FILE?
...
}

void download(const char* file_to_write, const char* short_database, const char* addr, const char* msg) {
remove(DATABASE_FILE); // again?!?

struct FtpFile ftpfile={
DATABASE_FILE, /* name to store the file as if succesful */
// ^^^ which one? file_to_write or short_database
NULL
};

关于对使用 libcurl 下载的文件所做的更改不会生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17511790/

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