void process_file(char *fnm) { int i; int fsz; ftp_connect(); FtpOptions(FTPLIB_CALLBACK, (long) NULL, conn); if ((action == FTP_SEND) || (action == FTP_GET)) { if (action == FTP_SEND) { struct stat info; if (stat(fnm,&info) == -1) { perror(fnm); return; } if (S_ISDIR(info.st_mode)) { if (!ftpMkdir(fnm)) fprintf(stderr,"mkdir %s failed\n%s",fnm,FtpLastResponse(conn)); else if (ftplib_debug) fprintf(stderr,"Directory %s created\n",fnm); return; } fsz = info.st_size; } else { if (!FtpSize(fnm, &fsz, mode, conn)) fsz = 0; } if (ftplib_debug && fsz) { FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); } } switch (action) { case FTP_DIR : i = FtpDir(NULL, fnm, conn); break; case FTP_LIST : i = FtpNlst(NULL, fnm, conn); break; case FTP_SEND : i = FtpPut(fnm,fnm,mode,conn); if (ftplib_debug && i) printf("%s sent\n",fnm); break; case FTP_GET : i = FtpGet(fnm,fnm,mode,conn); if (ftplib_debug && i) printf("%s retrieved\n",fnm); break; case FTP_RM : i = FtpDelete(fnm,conn); if (ftplib_debug && i) printf("%s deleted\n", fnm); break; } if (!i) printf("ftp error\n%s\n",FtpLastResponse(conn)); }
void process_file(char *fnm) { int sts=0; fsz_t fsz; struct REMFILE *filelist = NULL; struct REMFILE rem; ftp_connect(); FtpClearCallback(conn); if ((action == FTP_SEND) || (action == FTP_GET) || (action == FTP_RM)) { if (action == FTP_SEND) { struct stat info; if (stat(fnm,&info) == -1) { perror(fnm); return; } if (S_ISDIR(info.st_mode)) { if (!FtpMkdir(fnm, conn)) fprintf(stderr,"mkdir %s failed\n%s",fnm,FtpLastResponse(conn)); else if (ftplib_debug) fprintf(stderr,"Directory %s created\n",fnm); return; } fsz = info.st_size; } else { if (!wildcard) { struct REMFILE *f; f = (struct REMFILE *) malloc(sizeof(struct REMFILE)); memset(f,0,sizeof(struct REMFILE)); f->next = filelist; filelist = f; f->fnm = strdup(fnm); } else { netbuf *dir; char *buf; if (!FtpAccess(fnm, FTPLIB_DIR, FTPLIB_ASCII, conn, &dir)) { fprintf(stderr,"error requesting directory of %s\n%s\n", fnm, FtpLastResponse(conn)); return; } buf = malloc(DIRBUF_SIZE); while (FtpRead(buf, DIRBUF_SIZE, dir) > 0) { struct REMFILE *f; char *p; f = (struct REMFILE *) malloc(sizeof(struct REMFILE)); memset(f,0,sizeof(struct REMFILE)); f->next = filelist; p = strchr(buf,'\n'); if (p) *p = '\0'; f->fnm = strdup(buf); filelist = f; } free(buf); FtpClose(dir); } } } switch (action) { case FTP_DIR : sts = FtpDir(NULL, fnm, conn); break; case FTP_LIST : sts = FtpNlst(NULL, fnm, conn); break; case FTP_SEND : rem.next = NULL; rem.fnm = fnm; rem.fsz = fsz; fsz /= 100; if (fsz > 100000) fsz = 100000; if (ftplib_debug && fsz) { FtpCallbackOptions opt; opt.cbFunc = log_progress; opt.cbArg = &rem; opt.idleTime = 1000; opt.bytesXferred = fsz; FtpSetCallback(&opt,conn); } sts = FtpPut(fnm,strippath ? basename(fnm) : fnm,mode,conn); if (ftplib_debug && sts) printf("%s sent\n",fnm); break; case FTP_GET : while (filelist) { struct REMFILE *f = filelist; filelist = f->next; #if defined(__UINT64_MAX) if (!FtpSizeLong(f->fnm, &fsz, mode, conn)) #else if (!FtpSize(f->fnm, &fsz, mode, conn)) #endif fsz = 0; f->fsz = fsz; fsz /= 100; if (fsz > 100000) fsz = 100000; if ( fsz == 0 ) fsz = 32768; if (ftplib_debug) { FtpCallbackOptions opt; opt.cbFunc = log_progress; opt.cbArg = f; opt.idleTime = 1000; opt.bytesXferred = fsz; FtpSetCallback(&opt,conn); } sts = FtpGet(f->fnm,f->fnm,mode,conn); if (ftplib_debug && sts) printf("%s retrieved\n",f->fnm); free(f->fnm); free(f); } break; case FTP_RM : while (filelist) { struct REMFILE *f = filelist; filelist = f->next; sts = FtpDelete(f->fnm,conn); if (ftplib_debug && sts) printf("%s deleted\n", f->fnm); free(f->fnm); free(f); } break; } if (!sts) printf("ftp error\n%s\n",FtpLastResponse(conn)); return; }
void process_file(char *fnm) { int sts = 0; int fsz; struct REMFILE *filelist = NULL; struct REMFILE rem; ftp_connect(); FtpOptions(FTPLIB_CALLBACK, (long) NULL, conn); if ((action == FTP_SEND) || (action == FTP_GET)) { if (action == FTP_SEND) { struct stat info; if (stat(fnm, &info) == -1) { perror(fnm); return; } if (S_ISDIR(info.st_mode)) { if (!ftpMkdir(fnm)) fprintf(stderr, "mkdir %s failed\n%s", fnm, FtpLastResponse(conn)); else if (ftplib_debug) fprintf(stderr, "Directory %s created\n", fnm); return; } fsz = info.st_size; } else { if (!wildcard) { struct REMFILE *f; f = (struct REMFILE *) malloc(sizeof(struct REMFILE)); memset(f, 0, sizeof(struct REMFILE)); f->next = filelist; filelist = f; f->fnm = strdup(fnm); } else { netbuf * dir; char *buf; if (!FtpAccess(fnm, FTPLIB_DIR, FTPLIB_ASCII, conn, &dir)) { fprintf(stderr, "error requesting directory of %s\n%s\n", fnm, FtpLastResponse(conn)); return; } buf = malloc(DIRBUF_SIZE); while (FtpRead(buf, DIRBUF_SIZE, dir) > 0) { struct REMFILE *f; char *p; f = (struct REMFILE *) malloc(sizeof(struct REMFILE)); memset(f, 0, sizeof(struct REMFILE)); f->next = filelist; p = strchr(buf, '\n'); if (p) *p = '\0'; f->fnm = strdup(buf); filelist = f; } free(buf); FtpClose(dir); } } } switch (action) { case FTP_DIR: sts = FtpDir(NULL, fnm, conn); break; case FTP_LIST: sts = FtpNlst(NULL, fnm, conn); break; case FTP_SEND: rem.next = NULL; rem.fnm = fnm; rem.fsz = fsz; fsz /= 10; if (fsz > 100000) fsz = 100000; if (ftplib_debug && fsz) { FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); FtpOptions(FTPLIB_CALLBACKARG, (long) &rem, conn); FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz, conn); } sts = FtpPut(fnm, fnm, mode, conn); if (ftplib_debug && sts) printf("%s sent\n", fnm); break; case FTP_GET: while (filelist) { struct REMFILE *f = filelist; filelist = f->next; if (!FtpSize(f->fnm, &fsz, mode, conn)) fsz = 0; f->fsz = fsz; fsz /= 10; if (fsz > 100000) fsz = 100000; if (ftplib_debug && fsz) { FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); FtpOptions(FTPLIB_CALLBACKARG, (long) f, conn); FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz, conn); } sts = FtpGet(f->fnm, f->fnm, mode, conn); if (ftplib_debug && sts) printf("%s retrieved\n", f->fnm); free(f->fnm); free(f); } break; case FTP_RM: while (filelist) { struct REMFILE *f = filelist; filelist = f->next; sts = FtpDelete(f->fnm, conn); if (ftplib_debug && sts) printf("%s deleted\n", f->fnm); free(f->fnm); free(f); } break; } if (!sts) printf("ftp error\n%s\n", FtpLastResponse(conn)); return; }