2

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.

poolie
  • 8,454
  • 1
  • 43
  • 69
Chandan
  • 146
  • 2
  • 15
  • 1
    Do you actually have a file named `cs1130218@palasi.cse.iitd.ernet.in:games.txt` in the current directory where `a.out` lives? If not, that easily explains why `fopen()` fails to open that file... – twalberg Feb 25 '15 at 19:02
  • Oh! I have framed the question wrong! Let me correct it. – Chandan Feb 25 '15 at 19:27

2 Answers2

4

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

Josh Kelley
  • 50,042
  • 19
  • 127
  • 215
  • I am trying to figure out how to use `librsync` in my application to sync with `rsync` on remote linux system..does this mean it wouldn't connect with `rsync` since they are not the same things? – zar Jun 08 '15 at 20:59
  • @zadane - From what I can tell from reading the docs, not directly, unless you implement the `rsync` protocol yourself. – Josh Kelley Jun 09 '15 at 01:03
1

Neither librsync nor fopen deal with remote files.

Look at using a virtual filesystem library like GVFS or KIO instead: these can open files over SFTP and you can then pass them to librsync.

poolie
  • 8,454
  • 1
  • 43
  • 69
  • Yes, this is what I need. But I am unable to find any help on how to use it in c++. Can you please help me on that? – Chandan Mar 02 '15 at 15:48
  • FuSE may be the easiest solution. But it's really a separate question from librsync. – poolie Jun 07 '15 at 03:20