变化正在用的libcurl不生效下载的文件进行 [英] Changes being made to a file downloaded with libcurl don't take effect

查看:168
本文介绍了变化正在用的libcurl不生效下载的文件进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我更详细地解释。我想写下载从远程FTP服务器上的文件,追加一行到它的结束程序,然后重新上传它。文件操作的工作,和文本被附加到文件并重新上传的,但是当我再次下载该文件,没有文本被追加。我写了一个小的测试程序来证明这一点;这里的code。在引擎收录:

Let me explain in more detail. I'm trying to write a program that downloads a file from a remote FTP server, appends one line to the end of it, and then re-uploads it. The file operations work, and the text is appended to the file and re-uploaded, but when I download the file again, no text was appended. I've written a small test program to demonstrate this; here's the code at Pastebin:

http://pastebin.com/r07TkxEK

程序打印两个初始运行和后续运行::

The program prints the following output on both the initial run and subsequent runs::

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.

如果该程序的工作原理,从随后的运行输出的

If the program works, the output from the subsequent run should be:

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 功能。我一直在做的一切人道可能找出为什么发生这种情况,但没有成功。如果有人知道的任何的关于为什么这不工作,我很想知道。我被支付给编写这个程序,我知道我必须尽快找到解决的办法......

Because the data is written to the file and re-uploaded (I know this because the uploaded file is a greater size than the downloaded file) I assume the upload worked; my suspicion is that the problem lies in the download process and/or the curl_database_write function. I've been doing everything humanely possible to find out why this is happening, to no avail. If anyone knows anything about why this isn't working, I'd love to know. I'm being paid to write this program, and I know I've got to find a solution soon...

推荐答案

你是不是在下载使用short_database也不是file_to_write() - 函数。所以你从FTP服务器,而不是musiclist.txt下载/tmp/musiclist.txt。

you are not using "short_database" nor "file_to_write" in your download()-function. So you download /tmp/musiclist.txt from the ftp-server instead of musiclist.txt.

你应该检查你的定义,而当你使用一个定义,当你使用stringvariable,当你使用的参数

you should check your defines, and when you use a define and when you use a stringvariable and when you use parameters

#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不生效下载的文件进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆