home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------*
- * put.c -- send a file to a remote node
- *
- * Usage: put filename.ext \\nodeid
- *
- * The remote node must run 'get' to complete the transfer.
- * filename.ext and \\nodeid are command line arguments.
- *
- * Compiler: Microsoft C Version 5.0.
- *
- * Tom Nolan 7/12/89
- *
- *-------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <io.h>
- #include "netbios.h"
-
- void nsend(char *fname, char *node);
- void usage(void);
-
- typedef struct /* network information block definition */
- {
- char fname[MAXPATH]; /* file name for transmission */
- long fsize; /* size of file in bytes */
- char sender[NODE_NAME_LEN]; /* name of sending node */
- char receiver[NODE_NAME_LEN]; /* name of receiving node */
- }
- NETINFO;
-
- char buf[4096]; /* buffer for send/receive data */
-
- #define diag printf /* remove "printf" to turn off diags */
-
- /*-------------------------------------------------------------------------*/
- main(int argc, char **argv)
- {
- if(argc != 3)
- usage(); /* too many cmd line args */
-
- if(!isnodename(argv[1]) && isnodename(argv[2])) /* 2nd arg is nodename? */
- nsend(argv[1], argv[2]); /* so send to that node */
- else
- usage();
- exit(0);
- }
-
- /*-------------------------------------------------------------------------*/
- void nsend(char *fname, char *node) /* network send */
- {
- NETINFO netinfo; /* network information block */
- int lsn; /* logical session number */
- FILE *fp; /* file stream pointer */
- int len; /* len of data read from file */
- NCB ncb; /* network command block */
-
- fp = fopen(fname, "rb"); /* attempt to open file */
- if(!fp)
- {
- printf("File %s does not exist\n", fname);
- exit(1);
- }
-
- strcpy(netinfo.fname, fname); /* copy name of file */
- netinfo.fsize = filelength(fileno(fp)); /* ..size of file */
- strncpy(netinfo.receiver, node, NODE_NAME_LEN); /* ..and intended rcvr */
-
- diag("Posting receive\n");
- clear_ncb(&ncb); /* issue receive datagram */
- nw_recv_datagram(&netinfo, sizeof(netinfo), &ncb);
- diag("Sending datagram\n");
- while(ncb.cmdcplt == 0xff) /* send our request until */
- send_datagram(node, &netinfo, sizeof(netinfo)); /* an answer comes */
-
- while((lsn = call(netinfo.receiver, netinfo.sender)) == 0)
- ; /* call receiving node */
-
- diag("Communicating on LSN %d\n", lsn);
-
- printf("Packets:");
- while(netinfo.fsize > 0) /* send the whole file */
- {
- diag(".");
- len = fread(buf, 1, sizeof(buf), fp); /* a buffer at a time */
- send(lsn, buf, len);
- netinfo.fsize -= len;
- }
-
- receive(lsn, 0, 0); /* make sure our session is */
- fclose(fp); /* closed correctly */
- printf("\nSent file %s\n", fname);
- }
-
- /*-------------------------------------------------------------------------*/
- void usage(void)
- {
- printf( "Put v1.00 T. Nolan - 7/12/89\n"
- "usage:\n\n"
- "put filename.ext \\nodeid - send filename.ext to nodeid\n"
- "Run put and get on both nodes to transfer a file.\n");
- exit(1);
- }