home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95 / autotel.ksc < prev    next >
Text File  |  2020-01-01  |  4KB  |  94 lines

  1. ; Illustration of scripted Telnet login using K95 1.1.19.
  2. ;
  3. ; Optional command-line parameters:
  4. ;  1. Hostname or address
  5. ;  2. Username on host
  6. ;  3. Password on host
  7. ;
  8. ; Parameters not supplied are prompted for.
  9. ; Uses Telnet port only since a login dialog is assumed.
  10. ; Write a different script for accessing non-Telnet ports.
  11. ;
  12. ; WARNING: This is just an illustration.  It works with most servers,
  13. ; but is not general enough to work with all.  Prompts might be different,
  14. ; some terminal-related escape sequences might need to be exchanged, etc.
  15. ; See Chapter 19 of "Using C-Kermit" for details.
  16. ;
  17. define badversion echo Sorry - K95 1.1.19 or later required., exit
  18. if not equal "\v(program)" "C-Kermit" badversion
  19. if < \v(xversion) 1119 badversion
  20.  
  21. check network
  22. if fail stop 1 { Sorry, this version of Kermit does not support TCP/IP.}
  23. set network type tcp/ip
  24. if fail stop 1 { Sorry, this version of Kermit does not support TCP/IP.}
  25.  
  26. while not def \%1 {                    ; If hostname/address not supplied
  27.     ask \%1 { Host: }                  ; prompt for one until we get it.
  28.     if > \fsplit(\%1) 1 {              ; Allow only one "word" here.
  29.         echo Just the address please.  ; E.g. no TCP port number.
  30.         undef \%1
  31.     }
  32. }
  33. if not def \%2 {                       ; If username not supplied
  34.     ask \%2 { User [\v(user)]: }       ; Prompt for one, but default
  35.     if not def \%2 assign \%2 \v(user) ; to local user ID.
  36. }
  37. set telnet environment user \%2        ; Make sure correct userid is sent
  38.  
  39. ; To force the remote host to issue a login (username) prompt, uncomment
  40. ; the following command:
  41. ;
  42. ;;; set login userid
  43.  
  44. ; This script assumes that authenticated logins are not being performed
  45. ; via Kerberos, SRP, or any other supported method.
  46.  
  47. set telopt start-tls refuse            ; Do not use START_TLS option
  48. set telopt authentication refuse       ; Do not use AUTH option
  49. set telopt encrypt refuse refuse       ; Do not use ENCRYPT option
  50.  
  51. echo Connecting to \%1 as user \%2...
  52.  
  53. set host \%1 23 /telnet                ; Force Telnet protocol negotiations
  54. if fail stop 1 Can't open Telnet connection to \%1.
  55.  
  56. ; Prompt for password if necessary but only after connection is made
  57. ; (because there's no point in asking for it if the connection failed).
  58.  
  59. while not defined \%3 {
  60.     askq \%3 { Password for \%2 at \%1: }
  61. }
  62. set input echo off                     ; Don't echo scripted interactions.
  63.  
  64. ; Note that some Telnet servers get your user ID automatically in Telnet
  65. ; negotiations and so only prompt for Password:, so look for both at once.
  66. ; Also allow username prompt to be "login:" (UNIX) or "Username:" (VMS).
  67. ; Also allow for the fact that some servers prompt "Password for <username>:",
  68. ; whereas most others prompt just "Password:".
  69. ;
  70. minput 20 login: Username: Password: {Password for \%2:}
  71. if fail stop 1 Timed out waiting for initial prompt: \v(inwait) sec.
  72. if ( = \v(minput) 1 || = \v(minput) 2 ) {
  73.     lineout \%2                        ; User ID required - send it.
  74.     minput 10 Password: {Password for \%2:}
  75.     if fail stop 1 Timed out waiting for Password prompt: \v(inwait) sec.
  76. }
  77. lineout \%3                            ; Send password
  78. undef \%3                              ; Erase password from memory
  79. ;; set exit on-disconnect on           ; Exit automatically if connection lost.
  80.  
  81. ; The CONNECT command sends you online for an interactive session.  Instead
  82. ; of CONNECT, you can substitute additional scripting for automation of any
  83. ; interactions you would do by hand: use INPUT, OUTPUT, IF FAIL (or IF
  84. ; SUCCESS), and other scripting commands for this.  In a common example,
  85. ; you can start a Kermit server on the remote end and then transfer and/or
  86. ; manage remote files from this script.
  87.  
  88. connect
  89.  
  90. ; At this point, escaping back while the connection is open will give you
  91. ; the K-95> command prompt unless you include additional commands below.
  92.  
  93. End ; of Kermit sample Telnet script.
  94.