home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / ci211.zip / BBSBAK.PRG < prev    next >
Text File  |  1995-04-22  |  4KB  |  169 lines

  1. *
  2. * This short example demonstrates a simple method of communicating with
  3. * CopyIt/2 from a TDBS application.
  4. *
  5. * This program copies all files from the BBS machine to a directory
  6. * on the server retaining the directory structure. This program will be
  7. * able to copy while the BBS is running.  Because TDBS cannot make
  8. * directories, it sends a request to CopyIt/2, which issues the command.
  9. *
  10.  
  11. public BBS_drive, server_dir, CI2Path, TempPath, error
  12.  
  13. BBS_drive = "C:"              && drive to be backed up
  14. server_dir = "w:\BBSBAK"      && Destination for backup files
  15. CI2Path = "w:\ci2\"           && Location of CopyIt/2
  16.  
  17. * The variable "TempPath" is essentially the communications directory
  18. * and where you will copy files
  19. TempPath = "w:\temp\"+uline() && Directory for temporary communication files
  20.  
  21. ON ESCAPE QUIT
  22. ON ERROR error = error()
  23.  
  24. ? "Backing up TBBS machine to SERVER."
  25. ? ""
  26.  
  27. *
  28. * The database file "BAKDIRS.DBF" lists the files and directories that
  29. * should be backed up.  If the entry ends in a backslash, a directory is
  30. * assumed, and all files within that path, including subdirectories, are
  31. * included. All entries must begin with a backslash or drive letter, and 
  32. * include the full DOS pathname.
  33. * NOTE: Use the free VIEWDBF program to modify "BBSBAK.DBF".
  34. *       VIEWDBF can be downloaded from our BBS.
  35. *
  36.  
  37. use "BAKDIRS.DBF"
  38.  
  39. do while recno() <= lastrec()
  40.   path = rtrim(dir)
  41.   if right(path,1) = "\"
  42.  
  43.     * This entry is a directory... copy everything in it.
  44.     do CopyDir with path
  45.   else
  46.  
  47.     * This entry is a file... print its name and copy to SERVER
  48.     ? BBS_drive+path
  49.     copy file (BBS_drive+path) to (server_dir+path)
  50.   endif
  51.   skip
  52. enddo
  53.  
  54. quit
  55.  
  56.  
  57. *********
  58. procedure CopyDir
  59. *********
  60. parameters DirName
  61. private filename, filedata
  62.  
  63.   ? "["+DirName+"]"
  64.  
  65.   * Make sure the directory exists
  66.   FileName = findfirst(filedata,server_dir+left(dirname,len(dirname)-1),"X....",attr)
  67.   if empty(FileName)
  68.     ? "Making "+server_dir+DirName
  69.     do MakeDir with DirName
  70.   endif
  71.  
  72.   * Search for files within the directory
  73.   filename = findfirst(filedata,BBS_drive+dirname+"*.*","X....",attr)
  74.   do while .not. empty(filename)
  75.     if substr(attr,2,1) = "X"
  76.       if .not. Filename = "."
  77.       
  78.         * If the file is another subdirectory... recursively copy
  79.         do CopyDir with DirName+FileName+"\"
  80.       endif
  81.     else
  82.       if .not. right(filename,3) = "$$$"
  83.  
  84.         * Copy the file to Destination, as long as it is not a temporary file
  85.         error = 0
  86.         ? BBS_drive+dirname+filename
  87.         copy file (BBS_drive+dirname+filename) to (server_dir+DirName+filename)
  88.         if error > 0
  89.           ?? " WARNING: Copy Failed."
  90.         endif
  91.       endif
  92.     endif
  93.     filename = findnext(filedata,attr)
  94.   enddo
  95. return
  96.  
  97. *
  98. * Procedure: MakeDir - Create a request file that will be copied to
  99. *            the directory where CopyIt/2 is running.
  100. *
  101.  
  102. *********
  103. procedure MakeDir
  104. *********
  105. parameters ReqDir
  106.   
  107.   * Create the request
  108.   fcreate rHandle (CI2Path+"req" + uline()+".tmp") 13
  109.   flwrite rHandle Dummy "COMPATH "+TempPath + chr(13) + chr(10)
  110.  
  111.   flwrite rHandle Dummy "SHELL MD "+server_dir+left(ReqDir,len(ReqDir)-1)
  112.   fclose rHandle
  113.  
  114.   * Erase any response that may be left over from a previous request
  115.   erase (TempPath+"\response.flg")
  116.   
  117.   * Copy the request to CopyIt/2
  118.   rename (CI2Path+"req"+uline()+".tmp") to (CI2Path+"req"+uline()+".ci2")
  119.   ReqOK = .f.
  120.   do WaitForServerResponse
  121.   if .not. ReqOK
  122.     ? "Server failed to make directory: "+ReqDir
  123.     key = inkey(3)
  124.   endif
  125. return
  126.  
  127. *********
  128. procedure WaitForServerResponse
  129. *********
  130. private StartTime, ResFile
  131.  
  132.   if file(CI2Path+"noserver.flg")
  133.     ? "The server is not active at this time."
  134.     key = inkey(3)
  135.     ReqOK = .f.
  136.     return
  137.   endif
  138.   
  139.   * Wait for a response from CopyIt/2
  140.   StartTime = seconds()
  141.   do while .t.
  142.     
  143.     * Pause for three seconds
  144.     x = 0
  145.     do while x < 5
  146.       x = x+1
  147.       key = inkey(1)
  148.  
  149.       * if escape is hit, abort
  150.       if key = 27
  151.         return
  152.       endif
  153.     enddo
  154.     
  155.     * If response is found, exit with good status
  156.     if file(TempPath+"\response.flg")
  157.       ReqOK = .t.
  158.       exit
  159.     endif
  160.  
  161.     * If two minutes has passed, abort
  162.     if seconds() > StartTime + 120
  163.       return
  164.     endif
  165.   enddo
  166.   
  167.   * clean up the response
  168. return
  169.