如何使用 librsync 函数打开远程文件?

How to use librsync functions to open remote files?

我正在使用 librsync 库来维护文件版本。我无法从网络打开文件。

示例(创建签名文件):

int main(int argc, char** argv)//FILE *original, FILE *signature)
{
    if(argc != 2)
    {
        cout<<"Enter the original file name."<<endl;
        exit(1);
    }

    FILE *fpa;
    fpa = fopen(argv[1],"r");

    if(fpa==NULL)
    {
        cout<<"ERROR"<<endl;
        exit(1);
    }

    FILE *fps;
    fps = fopen("sig.sig","w+");


    rs_result res = rs_sig_file(fpa, fps, 1,2,NULL);

    fclose(fpa);
    fclose(fps);

    printf("Result code: %d\n", res);

    return 0;
}

当我 运行 带有网络文件参数的程序时,例如

./a.out cs1130218@palasi.cse.iitd.ernet.in:games.txt

fpa 为 NULL。

我猜 fopen 不是为通过网络打开文件而设计的。我需要一个可以做到这一点的命令。 c/c++ 中的任何命令。 你可以清楚地看到我想用程序做什么。

"I need a command which can open files over a network" 确实是,真的 高级操作,因此,它掩盖了各种细节:应该使用什么样的网络协议?身份验证应该如何处理?网络错误应该如何处理?打开文件后应该做什么:读取/写入/两者,顺序还是随机?

librsync 相对较低级别,甚至不会尝试自己回答这些问题。 Its README 说明:

librsync does not implement the rsync wire protocol. If you want to talk to an rsync server to transfer files you'll need to shell out to rsync. librsync is for building other programs that transfer files as efficiently as rsync. You can use librsync to make backup tools, distribute binary patches to programs, or sync directories to a server or between peers.

要通过网络打开文件,您需要实施自己的服务器和线路协议,或者您需要 shell 输出诸如 rsync 之类的命令来处理这些细节你(而且,如果你的大部分逻辑都在 shell 输出到其他命令,C++ 可能不是完成这项工作的最佳工具)。

librsyncfopen 都不处理远程文件。

考虑使用像 GVFS 或 KIO 这样的虚拟文件系统库:它们可以通过 SFTP 打开文件,然后您可以将它们传递给 librsync。