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

  1. #!/usr/local/bin/kermit
  2. ;
  3. ; f t p s y n c d o w n
  4. ;
  5. ; Synchronizes a local directory from a directory on an FTP server.
  6. ;  . Server files that don't exist locally are downloaded.
  7. ;  . Server files that exist locally are downloaded only if newer.
  8. ;  . Local files that don't exist on the server are deleted.
  9. ;  . Server file timestamps are preserved (if server supports MDTM).
  10. ;  . Server file permissions are not preserved (FTP doesn't allow that).
  11. ;  . Ditto for file owner, group, ACLs, etc.
  12. ;  . Works across platforms via automatic text/binary mode switching.
  13. ;  . Works quietly but keeps a log of what it did.
  14. ;
  15. ; Recursive directory tree synchronization can be done too, if the
  16. ; server supports it.  Simply add "/recursive" to the mget command
  17. ; and change the "\ffiles()" invocation to "\frfiles()".
  18. ; Requires: C-Kermit 80 or later or K95 2.0 or later
  19. ;
  20. ; F. da Cruz, Columbia University, 24 Feb 2003
  21.  
  22. ; Parameters - Change as needed (or turn them into arguments)
  23.  
  24. .host = kermit.columbia.edu         ; Change to desired host
  25. .rdirectory = kermit/g              ; Change to desired host directory
  26. .ldirectory = ~/g                   ; Change to desired local directory
  27. .logfile := \v(home)ftpsync.log     ; Change to desired logfile name
  28.  
  29. ; End of parameter defintions.
  30.  
  31. set transaction-log brief           ; Choose brief transaction-log format
  32. set exit warning off                ; No "OK to exit?" prompts
  33. set quiet on                        ; Suppress progress messages
  34.  
  35. lcd \m(ldirectory)                  ; CD to desired local directory
  36. if fail exit 1 "LCD failed - \m(ldirectory)" ; Make sure we did
  37.  
  38. ftp open \m(host) /anonymous        ; Open and check anonymous FTP connection
  39. if fail exit 1 Login failed
  40. if not \v(ftp_loggedin) exit 1 "Anonymous Login failed"
  41.  
  42. log transactions \m(logfile)        ; Start log
  43.  
  44. ftp cd \m(rdirectory)               ; CD to desired server directory
  45. if fail exit 1 "FTP CD failed - \m(rdirectory)"
  46.  
  47. ftp mget /collision:overwrite /update * ; Get all server files in update mode
  48. if fail exit 1 "Mget failed"            ; Check for errors
  49.  
  50. ; Remove extraneous local files
  51.  
  52. for \%i 1 \ffiles(*,&a) 1 {         ; Loop through local files
  53.     ftp check \&a[\%i]              ; Does file exist on server
  54.     if fail {                       ; Yes - delete it
  55.         ldelete \&a[\%i]
  56.         if fail exit 1 Ldelete \&a[\%i] failed
  57.         writeln transaction-log "\v(ndate),\v(time),DELETED,\&a[\%i]"
  58.     }
  59. }
  60. bye                                 ; Disconnect from server
  61. close transaction-log               ; Close log
  62. cat \m(logfile)                     ; Display log
  63. exit 0
  64.