📄 xnftp.c
字号:
*dir = '/'; remote = dir+1; } else { getfilehandle("", remotehandle); } } else { printf("No remote name specified\n"); return; } bytessent = 0; gettimeofday(&start, (struct timezone *)0); alarm(0); if (strcmp(cmd,"STOR") == 0) { attrseq.length = 2; attrseq.sequence = attrvals; attrvals[0].type = Filing4_name; StringToAttr(remote, &attrvals[0]); attrvals[1].type = Filing4_type; LongCardinalToAttr(typevalue, &attrvals[1]); storeresults = Filing4_Store(connected, storeproc, remotehandle, attrseq, nullControls, BulkData1_immediateSource, session); alarm(continuetime); freefilehandle(storeresults.file); } else if (strcmp(cmd,"MKDIR") == 0) { attrseq.length = 3; attrseq.sequence = attrvals; attrvals[0].type = Filing4_name; StringToAttr(remote, &attrvals[0]); attrvals[1].type = Filing4_isDirectory; BooleanToAttr(1, &attrvals[1]); attrvals[2].type = Filing4_type; LongCardinalToAttr(Filing4_tDirectory, &attrvals[2]); createresults = Filing4_Create(connected, NULL, remotehandle, attrseq, nullControls, session); alarm(continuetime); freefilehandle(createresults.file); } else { printf("unrecognized command %s\n",cmd); alarm(continuetime); } gettimeofday(&stop, (struct timezone *)0); freefilehandle(remotehandle); if (bytessent > 0 && verbose) ptransfer("sent", bytessent, &start, &stop);bad: if (closefunc != NULL && fin != NULL) (*closefunc)(fin); fin = NULL;}docd(dest) char *dest;{ Filing4_AttributeSequence attrseq; Filing4_AttributeTypeSequence typeseq; Filing4_AttributeType cdattrs[1]; Filing4_GetAttributesResults garesult; Filing4_Handle remotehandle, temphandle; char trydest[100]; int i; if (dest == (char*)NULL || *dest == '\0') { trydest[0] = '/'; /* assume absolute pathname */ strcpy(trydest+1,username.object); getfilehandle(trydest, remotehandle); } else getfilehandle(dest, remotehandle); typeseq.length = 1; typeseq.sequence = cdattrs; cdattrs[0] = Filing4_isDirectory; alarm(0); garesult = Filing4_GetAttributes(connected, NULL, remotehandle, typeseq, session); alarm(continuetime); for (i = 0; i < garesult.attributes.length; i++) { if (garesult.attributes.sequence[i].type == Filing4_isDirectory && AttrToBoolean(&(garesult.attributes.sequence[i]))) { copyhandle(temphandle, wdHandle); copyhandle(wdHandle, remotehandle); /* change dir */ if (verbose) dopwd(); freefilehandle(temphandle); /* free old wdHandle */ return; } } printf("%s is not a directory\n", dest); freefilehandle(remotehandle);}dopwd(){ Filing4_AttributeSequence attrseq; Filing4_AttributeTypeSequence typeseq; Filing4_AttributeType pwdattrs[1]; Filing4_GetAttributesResults garesult; if (wdHandle[0] == 0 && wdHandle[1] == 0) { printf("Remote working directory: /\n"); return; } typeseq.length = 1; typeseq.sequence = pwdattrs; pwdattrs[0] = Filing4_pathname; alarm(0); garesult = Filing4_GetAttributes(connected, NULL, wdHandle, typeseq, session); alarm(continuetime); if (garesult.attributes.length > 0 && garesult.attributes.sequence[0].type == Filing4_pathname) printf("Remote working directory: /%s\n", AttrToString(&(garesult.attributes.sequence[0]))); else printf("Remote working directory not set\n"); clear_Filing4_GetAttributesResults(&garesult);} dodelete(src) char *src;{ Filing4_Handle remotehandle; Filing4_AttributeSequence attrseq; Filing4_AttributeTypeSequence typeseq; Filing4_AttributeType delattrs[1]; Filing4_GetAttributesResults garesult; typeseq.length = 1; typeseq.sequence = delattrs; delattrs[0] = Filing4_isDirectory; getfilehandle(src, remotehandle); garesult = Filing4_GetAttributes(connected, NULL, remotehandle, typeseq, session); if (garesult.attributes.length > 0 && garesult.attributes.sequence[0].type == Filing4_isDirectory && AttrToBoolean(&(garesult.attributes.sequence[0]))) { if (!confirm("Delete directory", src)) return; } clear_Filing4_GetAttributesResults(&garesult); alarm(0); Filing4_Delete(connected, NULL, remotehandle, session); alarm(continuetime);}NYI(){ printf("Not yet implemented\n");}ptransfer(direction, bytes, t0, t1) char *direction; long bytes; struct timeval *t0, *t1;{ struct timeval td; long ms; float bs; tvsub(&td, t1, t0); ms = (td.tv_sec * 1000) + (td.tv_usec / 1000);#define nz(x) ((x) == 0 ? 1 : (x)) bs = ((1000. * (float) bytes) / (float) nz(ms)); printf("\n%ld bytes %s in %d.%02d seconds (%.2g Kbytes/s)\n", bytes, direction, td.tv_sec, td.tv_usec / 10000, bs / 1024.);}tvadd(tsum, t0) struct timeval *tsum, *t0;{ tsum->tv_sec += t0->tv_sec; tsum->tv_usec += t0->tv_usec; if (tsum->tv_usec > 1000000) tsum->tv_sec++, tsum->tv_usec -= 1000000;}tvsub(tdiff, t1, t0) struct timeval *tdiff, *t1, *t0;{ tdiff->tv_sec = t1->tv_sec - t0->tv_sec; tdiff->tv_usec = t1->tv_usec - t0->tv_usec; if (tdiff->tv_usec < 0) tdiff->tv_sec--, tdiff->tv_usec += 1000000;}nlistproc(attr) Filing4_AttributeSequence attr;{ int i; char *thisname; Filing4_AttributeType t; for (i = 0; i < attr.length; i++) { t = attr.sequence[i].type; if (t == Filing4_pathname) fputc('/', fout); if (t == Filing4_name || t == Filing4_pathname) { thisname = AttrToString(&attr.sequence[i]); fputs(thisname, fout); fputc('\n', fout); clear_String(&thisname); return; } }}listproc(attr) Filing4_AttributeSequence attr;{ int i; char *thisname = ""; Boolean istemp = 0; Boolean isdir = 0; LongCardinal thistype = 0; LongCardinal thissize = 0; Filing4_AttributeType t; char *filetypestr; char filetypebuf[20]; for (i = 0; i < attr.length; i++) { t = attr.sequence[i].type; if (t == Filing4_name || t == Filing4_pathname) thisname = AttrToString(&attr.sequence[i]); else if (t == Filing4_isDirectory) isdir = AttrToBoolean(&attr.sequence[i]); else if (t == Filing4_isTemporary) istemp = AttrToBoolean(&attr.sequence[i]); else if (t == Filing4_type) thistype = AttrToLongCardinal(&attr.sequence[i]); else if (t == Filing4_dataSize) thissize = AttrToLongCardinal(&attr.sequence[i]); } if (thistype == Filing4_tUnspecified) filetypestr = ""; else if (thistype == Filing4_tDirectory) filetypestr = "(dir.)"; else if (thistype == Filing4_tText) filetypestr = "(text)"; else if (thistype == Filing4_tSerialized) filetypestr = "(serial)"; else if (thistype == TYPE_VP) filetypestr = "(VP doc)"; else if (thistype == TYPE_Interpress) filetypestr = "(IPress)"; else if (thistype == TYPE_VPCanvas) filetypestr = "(VP can)"; else if (thistype == TYPE_VPDictionary) filetypestr = "(VP dic)"; else if (thistype == TYPE_VPMailNote) filetypestr = "(VPnote)"; else if (thistype == TYPE_VPReference) filetypestr = "(VP ref)"; else { sprintf(filetypebuf, "(%ld)", thistype); filetypestr = filetypebuf; } fprintf(fout, "%c%c%-8s%7ld %s\n", isdir?'D':' ', istemp?'T':' ', filetypestr, thissize, thisname); clear_String(&thisname);}#define MAXPACKS 20staticGetAttributeSequences(conn) CourierConnection *conn;{ int count, i; Unspecified buffer[MAXWORDS*MAXPACKS], *bp, *bufend; Filing4_StreamOfAttributeSequence attrs; bufend = buffer; bp = buffer+((MAXWORDS-1)*MAXPACKS); /* end of available space */ while ((count = BDTread(conn, (char*)bufend, MAXWORDS*sizeof(Unspecified))) > 0) { bufend += count/sizeof(Unspecified); bytessent += count; if (bufend > bp) { fprintf(stderr,"BDT read too big to fit\n"); BDTabort(conn); /* should clear out stuff here if we knew how much */ } } bp = buffer; while (bp < bufend) { bp += internalize_Filing4_StreamOfAttributeSequence(&attrs,bp); if (0 == (int) attrs.designator) { for (i=0; i < attrs.nextSegment_case.segment.length; i++) { (*ProcEachSeq)( attrs.nextSegment_case.segment.sequence[i]); } free(attrs.nextSegment_case.segment.sequence); } else { for (i = 0; i < attrs.lastSegment_case.length; i++) { (*ProcEachSeq)( attrs.lastSegment_case.sequence[i]); } free(attrs.lastSegment_case.sequence); return; } }}intgetBDTch(conn,bpp) CourierConnection *conn; u_char **bpp;{ static u_char buffer[SPPMAXDATA]; static int count; if (*bpp == NULL) {*bpp = buffer; count = 0;} if (*bpp >= buffer+count) { count=BDTread(conn,buffer,sizeof(buffer)); *bpp = buffer; } if (count <= 0) return(EOF); else return(*((*bpp)++)); }retrieveproc(conn) CourierConnection *conn;{ int count, ocount, ch, hashbytes; char buffer[SPPMAXDATA]; int charset, charset16; char *bp; switch (typevalue) { default : errno = ocount = 0; fflush(fout); while ((count = BDTread(conn, buffer, sizeof(buffer))) > 0) { if ((ocount = write(fileno(fout),buffer,count)) < 0) { perror("write"); BDTabort(conn); break; } bytessent += count; if (hash) { putchar('#'); fflush(stdout); } } if (count < 0) perror("netin"); break; case TYPE_VPMailNote : case TYPE_A : charset = 0; charset16 = 0; bp = NULL; hashbytes = 0; while ((ch = getBDTch(conn,&bp)) != EOF) { if (ch == '\377') { ch = getBDTch(conn,&bp); if (ch == '\377') charset16 = 1; else charset = ch; continue; } if (charset16) { charset = ch; ch = getBDTch(conn,&bp); } switch (charset) { case 0: /* normal character set -- minimal xlation */ if (ch == '\r') { ch = '\n'; while (hash && bytessent >= hashbytes){ putchar('#'); fflush(stdout); hashbytes += sizeof(buffer); } } else if (ch == ','+0200) ch = '_'; /* more mapping here */ putc(ch,fout); bytessent++; break; default: break; /* ignore */ } } if (hash) { while (bytessent < hashbytes) { putchar('#'); hashbytes += sizeof(buffer); } putchar('\n'); fflush(stdout); } /* if (count < 0) perror("netin"); */ break; }}storeproc(conn) CourierConnection *conn;{ int count, ocount; u_char buffer[SPPMAXDATA]; u_char *bp; errno = ocount = 0; clearerr(fin); switch (typevalue) { default : while ((count = fread(buffer,sizeof(char),SPPMAXDATA,fin)) > 0 && (ocount = BDTwrite(conn, buffer, count)) > 0) { bytessent += count; if (hash) { putchar('#'); fflush(stdout); } } break; case TYPE_VPMailNote : case TYPE_A : while ((count = fread(buffer,sizeof(char),SPPMAXDATA,fin)) > 0) { ocount = count; for (bp = buffer; count > 0; count--, bp++) { if (*bp == '\n') *bp = '\r'; else if (*bp == '_') *bp = ','+0200; /* more translations here */ } if ((ocount = BDTwrite(conn, buffer, ocount)) <= 0) break; bytessent += ocount; if (hash) { putchar('#'); fflush(stdout); } } break; } if (ocount < 0) { BDTabort(conn); perror("netout"); } else if (ferror(fin)) { BDTabort(conn); perror("fread"); } else BDTclosewrite(conn);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -