5 /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /* For copying and distribution information, please see the file */
7 /* <mit-copyright.h>. */
10 static char *rcsid_send_file_c = "$Header$";
13 #include <mit-copyright.h>
24 extern CONNECTION conn;
30 * (already sent) pathname file_size checksum
31 * <<< (int)code can we send it?
37 * >>> data (last block)
38 * <<< 0 (on final write, close, sync, checksum)
42 * 1 on error (file not found, etc)
46 send_file(pathname, target_path)
50 int n, fd, code, n_to_send;
54 string_alloc(&data, UPDATE_BUFSIZ);
57 fd = open(pathname, O_RDONLY, 0);
59 com_err(whoami, errno, "unable to open %s for read", pathname);
62 if (fstat(fd, &statb)) {
63 com_err(whoami, errno, "unable to stat %s", pathname);
67 n_to_send = statb.st_size;
69 sprintf(STRING_DATA(data), "XFER_002 %d %d %s",
70 n_to_send, checksum_file(pathname), target_path);
71 code = send_object(conn, (char *)&data, STRING_T);
73 com_err(whoami, code, " sending XFER_002 request");
77 code = receive_object(conn, (char *)&n, INTEGER_T);
79 com_err(whoami, code, " getting reply from XFER_002 request");
84 com_err(whoami, n, " transfer request (XFER_002) rejected");
89 code = receive_object(conn, (char *)&n, INTEGER_T);
91 com_err(whoami, connection_errno(conn), ": lost connection");
96 com_err(whoami, n, " from remote server: can't update %s",
102 while (n_to_send > 0) {
104 printf("n_to_send = %d\n", n_to_send);
106 n = read(fd, STRING_DATA(data), UPDATE_BUFSIZ);
108 com_err(whoami, errno, " reading %s for transmission", pathname);
112 MAX_STRING_SIZE(data) = n;
113 code = send_object(conn, (char *)&data, STRING_T);
115 com_err(whoami, connection_errno(conn), " transmitting file %s",
121 code = receive_object(conn, (char *)&n, INTEGER_T);
123 com_err(whoami, connection_errno(conn),
124 " awaiting ACK remote server during transmission of %s",
130 com_err(whoami, n, " from remote server during transmission of %s",
136 if (statb.st_size == 0) {
137 code = receive_object(conn, (char *)&n, INTEGER_T);
139 com_err(whoami, connection_errno(conn),
140 " awaiting ACK remote server after transmission of %s",
146 com_err(whoami, n, " from remote server after transmission of %s",