n_rcopyto(), n_rcopyfrom() - File transfer

SYNOPSIS

int n_rcopyto(SERVER *se,char *remotedest,char *localsrc);
int n_rcopyfrom(SERVER *se,char *localdest,char *remotesrc);


DESCRIPTION
These functions provide the ability to copy files between client and server. They are useful for inserting and retrieving INDIRECT fields. An indirect field will usually point to a file on the same machine as the server. So the existing connection may be used to transfer the file.

n_rcopyto() copies a file from the client to the server. n_rcopyfrom() copies a file from the server to the client. In both cases the second argument is the name of the file to create and the third argument is the file to read from.

Both functions return zero on error and non-zero on success.


EXAMPLE

/* insert a row with an indirect while creating the indirect file */

SERVER *se;
char *database, *table;
char *url, *remotefn, *localfn;
char *description;

   ...
   database=...
   table=...
   ...
   n_setdatabase(se,database);
   ...
   localfn=...
   description=...
   ...
   url=n_newindirect(se,database,table,(char *)NULL);
   remotefn=urlfn(url);
   if(!n_rcopyto(se,remotefn,localfn))
      puts("error");
   n_texis(se,"insert into %s values('%s','%s');",
           table,description,remotefn);
   free(remotefn);
   free(url);
   ...


EXAMPLE

/* query a table with an indirect field and download the file */

int
hit_handler(usr,tx,fl)
void *usr;  /* my user-data pointer */
TEXIS *tx;  /* Texis API handle */
FLDLST *fl; /* The field list data structure */
{
 USERDATA *myd=(USERDATA *)usr; /* cast the void into the real type */
 char *description, *remotefn;

      /* I know the resultant data types because I wrote the SELECT */
 description=(char *)fl->data[0];
 remotefn   =(char *)fl->data[1];
 printf("%s:\n",description);              /* print the description */
 if(!n_rcopyfrom(myd->se,"/tmp/scratch",remotefn)) /* get text file */
    puts("error");
 displayfile("/tmp/scratch");/* fictitious function to display a file */
 return(1);          /* tell the server to keep giving me more hits */
}

main()
{
 USERDATA mydata;

   mydata.se=...
   mydata.database=...
   mydata.table=...
   ...
   n_regtexiscb(mydata.se,&mydata,hit_handler);
   n_setdatabase(mydata.se,mydata.database);
   ...
   n_texis(mydata.se,
     "select description,text from %s where text like 'power struggle'",
     mydata.table);
   ...
}


SEE ALSO
n_newindirect()


Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.