0

让我更详细地解释一下。我正在尝试编写一个程序,该程序从远程 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功能上。我一直在尽人道地尽一切可能找出发生这种情况的原因,但无济于事。如果有人知道为什么这不起作用,我很想知道。我得到报酬来编写这个程序,我知道我必须尽快找到解决方案......

4

1 回答 1

0

您没有在下载()函数中使用“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
  };
于 2013-07-07T14:12:10.910 回答