7 static char *rcsid_send_file_c = "$Header$";
20 extern CONNECTION conn;
26 * (already sent) pathname file_size checksum
27 * <<< (int)code can we send it?
33 * >>> data (last block)
34 * <<< 0 (on final write, close, sync, checksum)
38 * 1 on error (file not found, etc)
42 send_file(pathname, target_path)
46 int n, fd, code, n_to_send;
50 string_alloc(&data, UPDATE_BUFSIZ);
53 fd = open(pathname, O_RDONLY, 0);
55 com_err(whoami, errno, "unable to open %s for read", pathname);
58 if (fstat(fd, &statb)) {
59 com_err(whoami, errno, "unable to stat %s", pathname);
63 n_to_send = statb.st_size;
65 sprintf(STRING_DATA(data), "XFER_002 %d %d %s",
66 n_to_send, checksum_file(pathname), target_path);
67 code = send_object(conn, (char *)&data, STRING_T);
69 com_err(whoami, code, " sending XFER_002 request");
73 code = receive_object(conn, (char *)&n, INTEGER_T);
75 com_err(whoami, code, " getting reply from XFER_002 request");
80 com_err(whoami, n, " transfer request (XFER_002) rejected");
85 code = receive_object(conn, (char *)&n, INTEGER_T);
87 com_err(whoami, connection_errno(conn), ": lost connection");
92 com_err(whoami, n, " from remote server: can't update %s",
98 while (n_to_send > 0) {
100 printf("n_to_send = %d\n", n_to_send);
102 n = read(fd, STRING_DATA(data), UPDATE_BUFSIZ);
104 com_err(whoami, errno, " reading %s for transmission", pathname);
108 MAX_STRING_SIZE(data) = n;
109 code = send_object(conn, (char *)&data, STRING_T);
111 com_err(whoami, connection_errno(conn), " transmitting file %s",
117 code = receive_object(conn, (char *)&n, INTEGER_T);
119 com_err(whoami, connection_errno(conn),
120 " awaiting ACK remote server during transmission of %s",
126 com_err(whoami, n, " from remote server during transmission of %s",
132 if (statb.st_size == 0) {
133 code = receive_object(conn, (char *)&n, INTEGER_T);
135 com_err(whoami, connection_errno(conn),
136 " awaiting ACK remote server after transmission of %s",
142 com_err(whoami, n, " from remote server after transmission of %s",