Changes being made to a file downloaded with libcurl don't take effect

左心房为你撑大大i 提交于 2019-12-13 05:54:56

问题


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.

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...


回答1:


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.

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
  };


来源:https://stackoverflow.com/questions/17511790/changes-being-made-to-a-file-downloaded-with-libcurl-dont-take-effect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!