if (ch == '\n') bump("Protocol error: Unexpected newline"); i = 0; action = ch; do {
}  if (attrs.permissions & 0040000) { struct scp_sftp_dirstack *newitem; struct fxp_handle *dirhandle; int nnames, namesize; struct fxp_name *ournames; struct fxp_names *names;   if (!scp_sftp_recursive) { tell_user(stderr, "pscp: %s: is a directory", fname); errs++; if (must_free_fname) sfree(fname); return 1; }   dirhandle = fxp_opendir(fname); if (!dirhandle) { tell_user(stderr, "scp: unable to open directory %s: %s", fname, fxp_error()); if (must_free_fname) sfree(fname); errs++; return 1; } nnames = namesize = 0; ournames = NULL; while (1) { int i;  names = fxp_readdir(dirhandle); if (names == NULL) { if (fxp_error_type() == SSH_FX_EOF) break; tell_user(stderr, "scp: reading directory %s: %s\n", fname, fxp_error()); if (must_free_fname) sfree(fname); sfree(ournames); errs++; return 1; } if (names->nnames == 0) { fxp_free_names(names); break; } if (nnames + names->nnames >= namesize) { namesize += names->nnames + 128; ournames = srealloc(ournames, namesize * sizeof(*ournames)); } for (i = 0; i < names->nnames; i++) ournames[nnames++] = names->names[i]; names->nnames = 0;	        fxp_free_names(names); } fxp_close(dirhandle);  newitem = smalloc(sizeof(struct scp_sftp_dirstack)); newitem->next = scp_sftp_dirstack_head; newitem->names = ournames; newitem->namepos = 0; newitem->namelen = nnames; if (must_free_fname) newitem->dirpath = fname; else newitem->dirpath = dupstr(fname); scp_sftp_dirstack_head = newitem;  act->action = SCP_SINK_DIR; act->buf = dupstr(stripslashes(fname)); act->name = act->buf; act->size = 0;	        act->mode = 07777 & attrs.permissions; if (scp_sftp_preserve && (attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) { act->atime = attrs.atime; act->mtime = attrs.mtime; act->settime = 1; } else act->settime = 0; return 0;  } else {  act->action = SCP_SINK_FILE; act->buf = dupstr(stripslashes(fname)); act->name = act->buf; if (attrs.flags & SSH_FILEXFER_ATTR_SIZE) { if (uint64_compare(attrs.size, uint64_make(0, ULONG_MAX)) > 0) { act->size = ULONG_MAX;    } else act->size = attrs.size.lo; } else act->size = ULONG_MAX;    act->mode = 07777 & attrs.permissions; if (scp_sftp_preserve && (attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) { act->atime = attrs.atime; act->mtime = attrs.mtime; act->settime = 1; } else act->settime = 0; if (must_free_fname) scp_sftp_currentname = fname; else scp_sftp_currentname = dupstr(fname); return 0; }  } else { int done = 0; int i, bufsize; int action; char ch;  act->settime = 0; act->buf = NULL; bufsize = 0;  while (!done) {
int scp_get_sink_action(struct scp_sink_action *act){    int done = 0;    int i, bufsize;    int action;    char ch;    act->settime = 0;    act->buf = NULL;    bufsize = 0;    while (!done) {	if (ssh_scp_recv(&ch, 1) <= 0)	    return 1;	if (ch == '\n')	    bump("Protocol error: Unexpected newline");	i = 0;	action = ch;	do {	    if (ssh_scp_recv(&ch, 1) <= 0)		bump("Lost connection");	    if (i >= bufsize) {		bufsize = i + 128;		act->buf = srealloc(act->buf, bufsize);	    }	    act->buf[i++] = ch;	} while (ch != '\n');	act->buf[i - 1] = '\0';	switch (action) {	  case '\01':		       /* error */	    tell_user(stderr, "%s\n", act->buf);	    errs++;	    continue;		       /* go round again */	  case '\02':		       /* fatal error */	    bump("%s", act->buf);	  case 'E':	    back->send("", 1);	    act->action = SCP_SINK_ENDDIR;	    return 0;	  case 'T':	    if (sscanf(act->buf, "%ld %*d %ld %*d",		       &act->mtime, &act->atime) == 2) {		act->settime = 1;		back->send("", 1);		continue;	       /* go round again */	    }	    bump("Protocol error: Illegal time format");	  case 'C':	  case 'D':	    act->action = (action == 'C' ? SCP_SINK_FILE : SCP_SINK_DIR);	    break;	  default:	    bump("Protocol error: Expected control record");	}	/*	 * We will go round this loop only once, unless we hit	 * `continue' above.	 */	done = 1;    }    /*     * If we get here, we must have seen SCP_SINK_FILE or     * SCP_SINK_DIR.     */    if (sscanf(act->buf, "%o %lu %n", &act->mode, &act->size, &i) != 2)	bump("Protocol error: Illegal file descriptor format");    act->name = act->buf + i;    return 0;}