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

  1. #!/usr/local/bin/kermit +
  2. #
  3. # i k s g e t  --  Get files from an Internet Kermit Service
  4. #
  5. # Helper for IKSD URLs.
  6. #
  7. # If necessary, change the top line to show the full pathname of C-Kermit 7.0.
  8. # Put this file in your PATH and give it execute permission (chmod +x).
  9. #
  10. # Usage:
  11. #
  12. #   iksget iksd://hostname/path/filespec
  13. #
  14. # (The "iksd:" and "//" are optional.)
  15. #
  16. # Separates the argument into access (IKSD://, optional), host, and path.
  17. # Logs into the IKSD (if any) at the given host as "anonymous" and gets the
  18. # given file(s).  Metacharacters in filespec must be quoted to prevent shell
  19. # expansion.  Example:
  20. #
  21. #   iksget "iksd://kermit.columbia.edu/kermit/f/ck*.txt"
  22. #
  23. # Illustrates:
  24. #  . Anonymous access to IKSD
  25. #  . Retrieving command-line arguments
  26. #  . Use of \fsplit() function for parsing strings
  27. #  . Compact substring notation
  28. #
  29. # Requires: C-Kermit 7.0
  30. #
  31. # Author: F. da Cruz, Columbia University, 5 March 2000
  32. #
  33. local \&a[] \%n host path rc            ; Local variables.
  34. set case off                            ; Caseless string comparisons.
  35.  
  36. if ( != 2 \v(argc) ) {                  ; Exactly one argument required.
  37.     exit 1 {Usage: \%0 <iksd-url>}
  38. }
  39. .\%n := \fsplit(\&_[1],&a,:)            ; Split access://host/path.
  40.  
  41. switch \%n {                            ; Verify result.
  42.   :0, exit 1 {Error: empty argument}    ; Nothing found.
  43.   :1, .host := \&a[1]                   ; IKSD: omitted - assume host/path.
  44.       break
  45.   :2, if ( not eq "\&a[1]" "iksd" ) {   ; Access: included.
  46.           exit 1 {Error: non-IKSD URL}  ; Make sure it's "IKSD:".
  47.       }
  48.       .host := \&a[2]                   ; Get host/path.
  49.       break
  50.   :default,                             ; Bad URL.
  51.       exit 1 {Error: too many :'s.}
  52. }
  53. while ( eq "\s(host[1:2])" "//" ) {     ; Strip any leading "//".
  54.     .host := \s(host[3])
  55. }
  56. .\%n = \findex(/,\m(host))              ; Find host/path separator.
  57. if ( < \%n 1 ) {                        ; Fail if none found.
  58.     exit 1 {Error: No filename given}
  59. }
  60. .path := \s(host[\%n+1])                ; This is the path.
  61. .host := \s(host[1:\%n-1])              ; This is the hostname.
  62.  
  63. set host \m(host):1649 /telnet          ; Connect to IKSD on the host.
  64. if fail {
  65.     exit 1 {Can't reach \m(host) - \v(errstring)}
  66. }
  67. set exit warning off                    ; Disable "OK to quit?" prompt.
  68.  
  69. remote login anonymous \v(user)@\v(host)  ; Log in as user "anonymous".
  70. if fail exit 1 {Anonymous login rejected} ; Check for failure.
  71.  
  72. set transfer display brief              ; Use BRIEF file-transfer display.
  73. set transfer bell off                   ; Don't ring the bell.
  74. get \m(path)                            ; GET requested file(s).
  75. .rc := \v(status)                       ; Retain status.
  76. bye                                     ; Sign off from server.
  77. exit \m(rc)                             ; Exit with GET return code.
  78.