/* * Receive files with Zmodem, Ymodem or Xmodem. * This receiver will figure out what to do, you should * be able to send anything. */ int zmrcvfiles(int want1k, int wantg) { int rc; Syslog('+', "%s: start receive", protname()); get_frame_buffer(); Rxtimeout = 10; if (secbuf == NULL) secbuf = malloc(MAXBLOCK+1); tryzhdrtype = ZRINIT; if ((rc = tryz()) < 0) { Syslog('+', "%s: could not initiate receive, rc=%d", protname(), rc); } else { if (rc == 0) { if (protocol == ZM_ZMODEM) { Syslog('+', "%s: switching to Ymodem", protname()); protocol = ZM_YMODEM; } rc = ymrcvfiles(want1k, wantg); goto fubar; } /* * Zmodem receiver */ switch (rc) { case ZCOMPL: rc = 0; break; case ZFILE: rc = rzfiles(); break; } } fubar: if (fout) { if (closeit(0)) { WriteError("%s: Error closing file", protname); } } if (secbuf) free(secbuf); secbuf = NULL; io_mode(0, 1); /* Normal raw mode */ /* * Some programs send some garbage after the transfer, eat these. * This also introduces a pause after the transfer, some clients * need this. */ purgeline(200); Syslog('+', "%s: end receive rc=%d", protname(), rc); return abs(rc); }
static int wcreceive(int argc, char **argp) { int c; if (Batch || argc == 0) { Crcflg = 1; if (!Quiet) fprintf(stderr, rbmsg, Progname, "sz"); if ((c = tryz())) { if (c == ZCOMPL) return OK; if (c == ERROR) goto fubar; c = rzfiles(); if (c) goto fubar; } else { for (;;) { if (wcrxpn(secbuf) == ERROR) goto fubar; if (secbuf[0] == 0) return OK; if (procheader(secbuf) == ERROR) goto fubar; if (wcrx() == ERROR) goto fubar; } } } else { Bytesleft = DEFBYTL; Filemode = 0; Modtime = 0L; procheader(""); strcpy(Pathname, *argp); checkpath(Pathname); fprintf(stderr, "\n%s: ready to receive %s\r\n", Progname, Pathname); if ((fout = fopen(Pathname, "w")) == NULL) return ERROR; if (wcrx() == ERROR) goto fubar; timing(1); } return OK; fubar: canit(); if (Topipe && fout) { pclose(fout); return ERROR; } if (fout) closeit(); return ERROR; }