You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

telnet.html 4.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Telnet Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="telnet">Telnet</a></h2>
  8. <h3>Description</h3>
  9. Task to automate a remote telnet session. The task uses
  10. nested <tt>&lt;read&gt;</tt> to indicate strings to wait for, and
  11. <tt>&lt;write&gt;</tt> tags to specify text to send.
  12. <p>If you do specify a userid and password, the system will
  13. assume a common unix prompt to wait on. This behavior can be easily over-ridden.</p>
  14. <p><b>Note:</b> This task depends on external libraries not included in the Ant distribution.
  15. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more information.</p>
  16. <h3>Parameters</h3>
  17. <table border="1" cellpadding="2" cellspacing="0">
  18. <tr>
  19. <th>Attribute</th>
  20. <th>Values</th>
  21. <th>Required</th>
  22. </tr>
  23. <tr>
  24. <td>userid</td>
  25. <td>the login id to use on the telnet server.</td>
  26. <td>Only if password is specified</td>
  27. </tr>
  28. <tr>
  29. <td>password</td>
  30. <td>the login password to use on the telnet server.</td>
  31. <td>Only if userid is specified</td>
  32. </tr>
  33. <tr>
  34. <td>server</td>
  35. <td>the address of the remote telnet server.</td>
  36. <td>Yes</td>
  37. </tr>
  38. <tr>
  39. <td>port</td>
  40. <td>the port number of the remote telnet server. Defaults to port 23.</td>
  41. <td>No</td>
  42. </tr>
  43. <tr>
  44. <td>initialCR</td>
  45. <td>send a cr after connecting (&quot;yes&quot;). Defaults to &quot;no&quot;.</td>
  46. <td>No</td>
  47. </tr>
  48. <tr>
  49. <td>timeout</td>
  50. <td>set a default timeout to wait for a response. Specified in seconds. Default is no timeout.</td>
  51. <td>No</td>
  52. </tr>
  53. </table>
  54. <h3><a name="nested">Nested Elements</a></h3>
  55. The commands to send to the server, and responses to wait for, are
  56. described as nested elements.
  57. <h4>read</h4>
  58. <p>declare (as a text child of this element) a string to wait for.
  59. The element supports the timeout attribute, which overrides any
  60. timeout specified for the task as a whole. It also has a <tt>string</tt>
  61. attribute, which is an alternative to specifying the string as
  62. a text element.
  63. </p>
  64. <i>Always declare an opening and closing
  65. &lt;read&gt; element to ensure that statements are not sent before
  66. the connection is ready, and that the connection is not broken before
  67. the final command has completed.
  68. </i>
  69. <h4>write</h4>
  70. <p>describes the text to send to the server. The <tt>echo</tt> boolean
  71. attribute controls whether the string is echoed to the local log;
  72. this is "true" by default
  73. </p>
  74. <h3>Examples</h3>
  75. A simple example of connecting to a server and running a command. This assumes
  76. a prompt of &quot;ogin:&quot; for the userid, and a prompt of &quot;assword:&quot;
  77. for the password.
  78. <blockquote><pre>
  79. &lt;telnet userid=&quot;bob&quot; password=&quot;badpass&quot; server=&quot;localhost&quot;&gt;
  80. &lt;read&gt;/home/bob&lt;/read&gt;
  81. &lt;write&gt;ls&lt;/write&gt;
  82. &lt;read string=&quot;/home/bob&quot;/&gt;
  83. &lt;/telnet&gt;
  84. </pre></blockquote>
  85. This task can be rewritten as:
  86. <blockquote><pre>
  87. &lt;telnet server=&quot;localhost&quot;&gt;
  88. &lt;read&gt;ogin:&lt;/read&gt;
  89. &lt;write&gt;bob&lt;/write&gt;
  90. &lt;read&gt;assword:&lt;/read&gt;
  91. &lt;write&gt;badpass&lt;/write&gt;
  92. &lt;read&gt;/home/bob&lt;/read&gt;
  93. &lt;write&gt;ls&lt;/write&gt;
  94. &lt;read&gt;/home/bob&lt;/read&gt;
  95. &lt;/telnet&gt;
  96. </pre></blockquote>
  97. A timeout can be specified at the &lt;telnet&gt; level or at the &lt;read&gt; level.
  98. This will connect, issue a sleep command that is suppressed from displaying and wait
  99. 10 seconds before quitting.
  100. <blockquote><pre>
  101. &lt;telnet userid=&quot;bob&quot; password=&quot;badpass&quot; server=&quot;localhost&quot; timeout=&quot;20&quot;&gt;
  102. &lt;read&gt;/home/bob&lt;/read&gt;
  103. &lt;write echo=&quot;false&quot;&gt;sleep 15&lt;/write&gt;
  104. &lt;read timeout=&quot;10&quot;&gt;/home/bob&lt;/read&gt;
  105. &lt;/telnet&gt;
  106. </pre></blockquote>
  107. The task can be used with other ports as well:
  108. <blockquote><pre>
  109. &lt;telnet port=&quot;80&quot; server=&quot;localhost&quot; timeout=&quot;20&quot;&gt;
  110. &lt;read/&gt;
  111. &lt;write&gt;GET / http/0.9&lt;/write&gt;
  112. &lt;write/&gt;
  113. &lt;read timeout=&quot;10&quot;&gt;&amp;lt;/HTML&amp;gt;&lt;/read&gt;
  114. &lt;/telnet&gt;
  115. </pre></blockquote>
  116. <p>
  117. To use this task against the WinNT telnet service, you need to configure the service to use
  118. classic authentication rather than NTLM negotiated authentication.
  119. This can be done in the Telnet Server Admin app:
  120. select "display/change registry settings", then "NTLM", then set the value of NTLM to 1.
  121. </p>
  122. <hr>
  123. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  124. Reserved.</p>
  125. </body>
  126. </html>