home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / io_putfiles.c < prev    next >
C/C++ Source or Header  |  2005-01-01  |  5KB  |  180 lines

  1. /* io_putfiles.c
  2.  *
  3.  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
  4.  * All rights reserved.
  5.  *
  6.  */
  7.  
  8. #include "syshdrs.h"
  9. #ifdef PRAGMA_HDRSTOP
  10. #    pragma hdrstop
  11. #endif
  12.  
  13. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  14. #    define ASCII_TRANSLATION 0
  15. #endif
  16.  
  17. #ifndef ASCII_TRANSLATION
  18. #    define ASCII_TRANSLATION 1
  19. #endif
  20.  
  21. #ifndef NO_SIGNALS
  22. #    define NO_SIGNALS 1
  23. #endif
  24.  
  25. #ifndef O_BINARY
  26.     /* Needed for platforms using different EOLN sequence (i.e. DOS) */
  27. #    ifdef _O_BINARY
  28. #        define O_BINARY _O_BINARY
  29. #    else
  30. #        define O_BINARY 0
  31. #    endif
  32. #endif
  33.  
  34. int
  35. FTPPutFiles3(
  36.     const FTPCIPtr cip,
  37.     const char *const pattern,
  38.     const char *const dstdir1,
  39.     const int recurse,
  40.     const int doGlob,
  41.     const int xtype,
  42.     int appendflag,
  43.     const char *const tmppfx,
  44.     const char *const tmpsfx,
  45.     const int resumeflag,
  46.     const int deleteflag,
  47.     const FTPConfirmResumeUploadProc resumeProc,
  48.     int UNUSED(reserved))
  49. {
  50.     FTPLineList globList;
  51.     FTPFileInfoList files;
  52.     FTPFileInfoPtr filePtr;
  53.     int batchResult;
  54.     int result;
  55.     const char *dstdir;
  56.     char dstdir2[512];
  57.  
  58.     LIBNCFTP_USE_VAR(reserved);
  59.     if (cip == NULL)
  60.         return (kErrBadParameter);
  61.     if (strcmp(cip->magic, kLibraryMagic))
  62.         return (kErrBadMagic);
  63.  
  64.     if (dstdir1 == NULL) {
  65.         dstdir = NULL;
  66.     } else {
  67.         dstdir = STRNCPY(dstdir2, dstdir1);
  68.         StrRemoveTrailingLocalPathDelim(dstdir2);
  69.     }
  70.  
  71.     (void) FTPLocalGlob(cip, &globList, pattern, doGlob);
  72.     if (recurse == kRecursiveYes) {
  73.         appendflag = kAppendNo;
  74.         (void) FTPLocalRecursiveFileList(cip, &globList, &files);
  75.         if (files.first == NULL) {
  76.             cip->errNo = kErrNoValidFilesSpecified;
  77.             return (kErrNoValidFilesSpecified);
  78.         }
  79.         (void) ComputeRNames(&files, dstdir, 0, 1);
  80.     } else {
  81.         (void) LineListToFileInfoList(&globList, &files);
  82.         (void) ComputeLNames(&files, NULL, NULL, 1);
  83.         (void) ComputeRNames(&files, dstdir, 0, 0);
  84.     }
  85.     DisposeLineListContents(&globList);
  86.  
  87. #if 0
  88.     for (filePtr = files.first; filePtr != NULL; filePtr = filePtr->next) {
  89.         PrintF(cip, "  R=%s, L=%s, 2=%s, size=%lld, mdtm=%u, type=%c\n",
  90.             filePtr->rname,
  91.             filePtr->lname,
  92.             filePtr->rlinkto ? filePtr->rlinkto : "",
  93.             filePtr->size,
  94.             (unsigned int) filePtr->mdtm,
  95.             filePtr->type
  96.         );
  97.     }
  98. #endif
  99.  
  100.     batchResult = kNoErr;
  101.     for (filePtr = files.first; filePtr != NULL; filePtr = filePtr->next) {
  102.         if (cip->connected == 0) {
  103.             if (batchResult == kNoErr)
  104.                 batchResult = kErrRemoteHostClosedConnection;
  105.             break;
  106.         }
  107.         if (filePtr->type == 'd') {
  108.             /* mkdir */
  109.             StrRemoveTrailingLocalPathDelim(filePtr->rname);
  110.             result = FTPMkdir(cip, filePtr->rname, kRecursiveNo);
  111.             if (result != kNoErr)
  112.                 batchResult = result;
  113. #ifdef HAVE_SYMLINK
  114.         } else if (filePtr->type == 'l') {
  115.             /* symlink */
  116.             /* no RFC way to create the link, though. */
  117.             if ((filePtr->rlinkto != NULL) && (filePtr->rlinkto[0] != '\0'))
  118.                 (void) FTPSymlink(cip, filePtr->rname, filePtr->rlinkto);
  119. #endif
  120.         } else if (recurse != kRecursiveYes) {
  121.             result = FTPPutOneF(cip, filePtr->lname, filePtr->rname, xtype, -1, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
  122.             if (files.nFileInfos == 1) {
  123.                 if (result != kNoErr)
  124.                     batchResult = result;
  125.             } else {
  126.                 if ((result != kNoErr) && (result != kErrLocalFileNewer) && (result != kErrRemoteFileNewer) && (result != kErrRemoteSameAsLocal))
  127.                     batchResult = result;
  128.             }
  129.             if (result == kErrUserCanceled)
  130.                 cip->cancelXfer = 1;
  131.             if (cip->cancelXfer > 0)
  132.                 break;
  133.         } else {
  134.             result = FTPPutOneF(cip, filePtr->lname, filePtr->rname, xtype, -1, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
  135.             if (files.nFileInfos == 1) {
  136.                 if (result != kNoErr)
  137.                     batchResult = result;
  138.             } else {
  139.                 if ((result != kNoErr) && (result != kErrLocalFileNewer) && (result != kErrRemoteFileNewer) && (result != kErrRemoteSameAsLocal))
  140.                     batchResult = result;
  141.             }
  142.             if (result == kErrUserCanceled)
  143.                 cip->cancelXfer = 1;
  144.             if (cip->cancelXfer > 0)
  145.                 break;
  146.         }
  147.     }
  148.     DisposeFileInfoListContents(&files);
  149.     if (batchResult < 0)
  150.         cip->errNo = batchResult;
  151.     return (batchResult);
  152. }    /* FTPPutFiles3 */
  153.  
  154.  
  155.  
  156.  
  157. int
  158. FTPPutFiles(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob)
  159. {
  160.     return (FTPPutFiles3(cip, pattern, dstdir, recurse, doGlob, kTypeBinary, 0, NULL, NULL, kResumeNo, kDeleteNo, kNoFTPConfirmResumeUploadProc, 0));
  161. }    /* FTPPutFiles */
  162.  
  163.  
  164.  
  165.  
  166. int
  167. FTPPutFiles2(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int appendflag, const char *const tmppfx, const char *const tmpsfx)
  168. {
  169.     return (FTPPutFiles3(cip, pattern, dstdir, recurse, doGlob, xtype, appendflag, tmppfx, tmpsfx, kResumeNo, kDeleteNo, kNoFTPConfirmResumeUploadProc, 0));
  170. }    /* FTPPutFiles2 */
  171.  
  172.  
  173.  
  174.  
  175. int
  176. FTPPutFilesAscii(const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob)
  177. {
  178.     return (FTPPutFiles3(cip, pattern, dstdir, recurse, doGlob, kTypeAscii, 0, NULL, NULL, kResumeNo, kDeleteNo, kNoFTPConfirmResumeUploadProc, 0));
  179. }    /* FTPPutFilesAscii */
  180.