home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / synchronize < prev    next >
Text File  |  2020-01-01  |  8KB  |  201 lines

  1. #!/usr/local/bin/wermit +
  2. ;
  3. ; s y n c h r o n i z e
  4. ;
  5. ; Synchronizes parallel directory trees over a Telnet connection.
  6. ;
  7. ; Requires: C-Kermit 7.0 Beta.07 or later.
  8. ; Author:   F. da Cruz, Columbia University Kermit Project
  9. ;
  10. ; Command-line parameters:
  11. ;  1. Root of source directory tree on local computer.
  12. ;  2. Root of destination directory tree on target computer.
  13. ;  3. Hostname or address of target computer.
  14. ;  4. Username on target host
  15. ;  5. Password on target host
  16. ;
  17. ; Parameters 2-5 are prompted for if not suplied.
  18. ;
  19. ; This script synchronizes parallel directory trees on two computers
  20. ; over a Telnet connection.  The two computers need not be running the
  21. ; same operating system.  For example, any pair from { Win32, UNIX, VMS }
  22. ; can be chosen, as long as they are running the required C-Kermit
  23. ; version.
  24. ;
  25. ;  . For shell logins, the remote prompt is assumed to be "$ ".
  26. ;    Change as needed (or use IKSD login).
  27. ;
  28. ;  . The root directory on the target host must exist (easy to
  29. ;    change).
  30. ;
  31. ;  . The synchronization is in one direction only: the target
  32. ;    is updated from the source.
  33. ;
  34. ;  . Subdirectories are created as needed at the destination.
  35. ;
  36. ;  . Files that exist in the destination tree that do not also
  37. ;    exist in the source tree are deleted.
  38. ;
  39. ;  . Files are transferred in update mode; only the source files
  40. ;    that are newer than the corresponding destination files are
  41. ;    sent.
  42. ;
  43. ;  . Backup files (*.~*~) are not sent.  All other files are sent.
  44. ;
  45. ;  . The destination TCP port is hardwired (Telnet or IKSD).
  46. ;
  47. ;  . A regular connection is made, rather than a secure one.
  48. ;    The password is transmitted in the clear.  This can be fixed
  49. ;    by using a Kerberized or SRP-enabled C-Kermit build and then
  50. ;    slightly modifying this script.
  51. ;
  52. ; Limitations:
  53. ;
  54. ;  . Filenames containing spaces cause trouble.  Avoid them.
  55. ;
  56. ;  . Empty source directories are not replicated at the target.
  57. ;
  58. ;  . Special characters in command line options might need to be
  59. ;    quoted according to the rules of your shell.  Also note the
  60. ;    use \fcontents() around variables containing directory names;
  61. ;    this is to prevent recursive evaluation when the directory
  62. ;    name contains backslashes (e.g. C:\WINDOWS\SYSTEM).
  63. ;
  64. ;  . C-Kermit 7.0 Beta.08 and earlier issue various gratuitous
  65. ;    and/or misleading messages; this is a cosmetic problem only,
  66. ;    fixed in Beta.09.
  67. ;
  68. ; Begin by checking C-Kermit version:
  69. ;
  70. define badversion echo Sorry - C-Kermit 7.0 or later required., exit
  71. if not equal "\v(program)" "C-Kermit" badversion
  72. if LLT \v(version) 70000 badversion
  73.  
  74. ; Define usage and fatal error macros.
  75.  
  76. define usage exit 1 {
  77.   Usage: sourcedir [ targetdir [ targethost [ username [ password ] ] ] ]
  78. }
  79. define giveup { bye, hangup, close, exit 1 {FATAL: \%1 (Connection closed)} }
  80.  
  81. ; Runtime parameters...
  82.  
  83. .iksd = 0                              ; Set to nonzero to use IKSD.
  84. .debug = 0                             ; Set to nonzero for debug messages.
  85.  
  86. ; Command-line parsing...
  87.  
  88. if not def \%1 usage                   ; Give usage message if no arguments.
  89. cd \fcontents(\%1)                     ; Change to source directory
  90. if fail exit 1 Can't CD to "\fcontents(\%1)" ; Failure is fatal
  91.  
  92. while not def \%3 {                    ; If hostname/address not supplied
  93.     ask \%1 { Host: }                  ; prompt for one until we get it.
  94.     if > \fsplit(\%3) 1 {              ; Allow only one "word" here.
  95.         echo Just the address please.  ; E.g. no TCP port number.
  96.         undef \%3
  97.     }
  98. }
  99. while not def \%2 {                    ; If target directory not supplied
  100.     ask \%2 { Directory on \%3: }      ; ask til we get it.
  101. }
  102. if not def \%4 {                       ; If username not supplied
  103.     ask \%4 { User [\v(user)]: }       ; Prompt for one, but default
  104.     if not def \%4 assign \%4 \v(user) ; to local user ID.
  105. }
  106. while not defined \%5 {                ; Ditto for password
  107.     askq \%5 { Password for \%4 at \%3: }
  108. }
  109. set telnet environment user \%4        ; Make sure correct userid is sent
  110. set exit warning off                   ; No "OK to exit?" prompts please
  111.  
  112. ; This script assumes that authenticated logins are not being performed
  113. ; via Kerberos, SRP, or any other supported method.  It can easily be
  114. ; modified to use Kerberos or SRP.
  115.  
  116. set telopt start-tls refuse            ; Do not use START_TLS option
  117. set telopt authentication refuse       ; Do not use AUTH option
  118. set telopt encrypt refuse refuse       ; Do not use ENCRYPT option
  119.  
  120. if \m(debug) {
  121.     echo Source directory: \fcontents(\%1)
  122.     echo Target directory: \fcontents(\%2)
  123.     echo Target host:      \fcontents(\%3)
  124.     echo User at host:     \fcontents(\%4)
  125.     echo IKSD:             \m(iksd)
  126.     set input echo on
  127. } else {
  128.     set input echo off
  129.     set quiet on
  130. }
  131.  
  132. if \m(iksd) {                          ; IKSD...
  133.     echo Connecting to \%3:kermit...
  134.     set host \%3 1649 /telnet
  135.     if fail exit 1 Can't open connection to iksd@\%3.
  136.     remote login \%4 \%5
  137.     if fail exit 1 Authentication failure
  138. } else {                               ; Regular shell login
  139.     echo Connecting to \%3:telnet...
  140.     set host \%3 23 /telnet
  141.     if fail exit 1 Can't open Telnet connection to \%3.
  142.     minput 20 login: Username: Password: {Password for \%3:}
  143.     if fail exit 1 Timed out waiting for initial prompt: \v(inwait) sec.
  144.     if ( = \v(minput) 1 || = \v(minput) 2 ) {
  145.     lineout \%4                    ; User ID required - send it.
  146.     minput 10 Password: {Password for \%4:}
  147.     if fail exit 1 Timed out waiting for Password prompt: \v(inwait) sec.
  148.     }
  149.     lineout \%5                        ; Send password
  150.     undef \%5                          ; Erase password from memory
  151.     input 60 {$ }                      ; *** Wait for shell prompt ***
  152.     if fail echo WARNING: No shell prompt ;  But ignore failure
  153.     lineout kermit -x                     ;  Start Kermit server
  154.     input 30 READY TO SERVE...            ;  Courtesy but not necessary
  155. }
  156.  
  157. ; Have a connection with Kermit server on the far end.
  158. ; The rest is easy...
  159.  
  160. .m1 := Can't CD to remote directory "\fcontents(\%2)"
  161. .m2 := WARNING: Update mode not negotiated - performing full transfer...
  162.  
  163. set transfer bell off                  ; Silence the bell
  164. set transfer display brief             ; Skip the fullscreen display.
  165.  
  166. rcd \fcontents(\%2)                    ; CD to remote target directory.
  167. if fail giveup {\m(m1)}                ; Failure is fatal
  168. rset file collision update             ; Use update mode (only send new files)
  169. rset server cd-message off             ; We don't need orientation messages
  170. if fail echo {\m(m2)}                  ; Failure is not fatal
  171. echo
  172. send /recursive /nobackup *            ; Send the source tree
  173. if fail giveup {SEND failed}           ; Update failed
  174.  
  175. ; Delete all files at the remote that do not exist locally...
  176.  
  177. ;;; forward fin                        ; Uncomment to skip deletion phase
  178.  
  179. echo
  180. echo DELETION PHASE: Searching \%3:\fcontents(\%2)...
  181. echo
  182. query kermit rfiles(*)                 ; Get recursive remote file list
  183. if fail giveup {QUERY failed}
  184. .\%n := \v(query)                      ; How many in list
  185. .\%m = 0                               ; How many deleted
  186. if \m(debug) echo REMOTE FILES = \%n   ; Debug message
  187. for \%i 1 \%n 1 {                      ; Loop through remote files
  188.     query kermit nextfile()            ; Next one
  189.     if \m(debug) echo \%i. \v(query)
  190.     if not exist \v(query) {           ; If it doesn't exist on this end...
  191.         rdelete \v(query)              ; Delete the one on the far end
  192.         if success increment \%m       ; Count it if deletion successful
  193.     }
  194. }
  195. if \%m echo
  196. echo DELETED: \%m                      ; Say how many were deleted
  197.  
  198. :FIN
  199. bye                                    ; Close the server
  200. exit 0                                 ; Update succeeded - done
  201.