c++librsync

How to use librsync functions to open remote files?


I am using librsync library for maintaining file versions. I am not able to open files from a network.

Example (creating signature file):

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

When I run the program with argument of a file over a network, e.g.

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

fpa is NULL.

I guess that fopen is not made for opening files over a network. I need a command which can do this. Any command in c/c++. You can clearly see what I want to do with the programme.


Solution

  • "I need a command which can open files over a network" is a really, really high-level operation, and as such, it glosses over all kinds of details: What kind of network protocol should be used? How should authentication be handled? How should network errors be handled? What should be done once the file is opened: read / write / both, sequential or random?

    librsync is relatively low-level and doesn't even try to answer these questions itself. Its README explains:

    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.

    To open files over a network, you'll need to implement your own server and wire protocol, or you'll need to shell out to commands like rsync that handle these details for you (and, if most of your logic is in shelling out to other commands, C++ may not be the best tool for the job).