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 5.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Telnet Task</title>
  20. </head>
  21. <body>
  22. <h2 id="telnet">Telnet</h2>
  23. <h3>Description</h3>
  24. <p>Task to automate a remote telnet session. The task uses nested <code>&lt;read&gt;</code> to
  25. indicate strings to wait for, and <code>&lt;write&gt;</code> tags to specify text to send.</p>
  26. <p>If you do specify a userid and password, the system will assume a common Unix prompt to wait
  27. on. This behavior can be easily overridden.</p>
  28. <p><strong>Note</strong>: This task depends on external libraries not included in the Apache Ant
  29. distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more
  30. information.</p>
  31. <h3>Parameters</h3>
  32. <table class="attr">
  33. <tr>
  34. <th scope="col">Attribute</th>
  35. <th scope="col">Values</th>
  36. <th scope="col">Required</th>
  37. </tr>
  38. <tr>
  39. <td>userid</td>
  40. <td>the login id to use on the telnet server.</td>
  41. <td>Only if <var>password</var> is specified</td>
  42. </tr>
  43. <tr>
  44. <td>password</td>
  45. <td>the login password to use on the telnet server.</td>
  46. <td>Only if <var>userid</var> is specified</td>
  47. </tr>
  48. <tr>
  49. <td>server</td>
  50. <td>the address of the remote telnet server.</td>
  51. <td>Yes</td>
  52. </tr>
  53. <tr>
  54. <td>port</td>
  55. <td>the port number of the remote telnet server.</td>
  56. <td>No; defaults to <q>23</q></td>
  57. </tr>
  58. <tr>
  59. <td>initialCR</td>
  60. <td>send a cr after connecting if <q>yes</q>.</td>
  61. <td>No; defaults to <q>no</q></td>
  62. </tr>
  63. <tr>
  64. <td>timeout</td>
  65. <td>set a default timeout to wait for a response. Specified in seconds.</td>
  66. <td>No; default is no timeout</td>
  67. </tr>
  68. </table>
  69. <h3 id="nested">Parameters specified as nested elements</h3>
  70. <p>The commands to send to the server, and responses to wait for, are described as nested
  71. elements.</p>
  72. <h4>read</h4>
  73. <p>declare (as a text child of this element) a string to wait for. The element supports
  74. the <var>timeout</var> attribute, which overrides any timeout specified for the task as a whole. It
  75. also has a <var>string</var> attribute, which is an alternative to specifying the string as a text
  76. element.</p>
  77. <p><em>Always declare an opening and closing <code>&lt;read&gt;</code> element to ensure that
  78. statements are not sent before the connection is ready, and that the connection is not broken before
  79. the final command has completed.</em></p>
  80. <h4>write</h4>
  81. <p>describes the text to send to the server. The <var>echo</var> boolean attribute controls whether
  82. the string is echoed to the local log; this is <q>true</q> by default.</p>
  83. <h3>Examples</h3>
  84. <p>A simple example of connecting to a server and running a command. This assumes a prompt
  85. of <q>ogin:</q> for the userid, and a prompt of <q>assword:</q> for the password.</p>
  86. <pre>
  87. &lt;telnet userid=&quot;bob&quot; password=&quot;badpass&quot; server=&quot;localhost&quot;&gt;
  88. &lt;read&gt;/home/bob&lt;/read&gt;
  89. &lt;write&gt;ls&lt;/write&gt;
  90. &lt;read string=&quot;/home/bob&quot;/&gt;
  91. &lt;/telnet&gt;</pre>
  92. <p>This task can be rewritten as:</p>
  93. <pre>
  94. &lt;telnet server=&quot;localhost&quot;&gt;
  95. &lt;read&gt;ogin:&lt;/read&gt;
  96. &lt;write&gt;bob&lt;/write&gt;
  97. &lt;read&gt;assword:&lt;/read&gt;
  98. &lt;write&gt;badpass&lt;/write&gt;
  99. &lt;read&gt;/home/bob&lt;/read&gt;
  100. &lt;write&gt;ls&lt;/write&gt;
  101. &lt;read&gt;/home/bob&lt;/read&gt;
  102. &lt;/telnet&gt;</pre>
  103. <p>A timeout can be specified at the <code>&lt;telnet&gt;</code> level or at
  104. the <code>&lt;read&gt;</code> level. This will connect, issue a <kbd>sleep</kbd> command that is
  105. suppressed from displaying and wait 10 seconds before quitting.</p>
  106. <pre>
  107. &lt;telnet userid=&quot;bob&quot; password=&quot;badpass&quot; server=&quot;localhost&quot; timeout=&quot;20&quot;&gt;
  108. &lt;read&gt;/home/bob&lt;/read&gt;
  109. &lt;write echo=&quot;false&quot;&gt;sleep 15&lt;/write&gt;
  110. &lt;read timeout=&quot;10&quot;&gt;/home/bob&lt;/read&gt;
  111. &lt;/telnet&gt;</pre>
  112. <p>The task can be used with other ports as well:</p>
  113. <pre>
  114. &lt;telnet port=&quot;80&quot; server=&quot;localhost&quot; timeout=&quot;20&quot;&gt;
  115. &lt;read/&gt;
  116. &lt;write&gt;GET / http/0.9&lt;/write&gt;
  117. &lt;write/&gt;
  118. &lt;read timeout=&quot;10&quot;&gt;&amp;lt;/HTML&amp;gt;&lt;/read&gt;
  119. &lt;/telnet&gt;</pre>
  120. <p>To use this task against the Windows NT telnet service, you need to configure the service to use
  121. classic authentication rather than NTLM negotiated authentication. This can be done in the Telnet
  122. Server Admin app: select <q>display/change registry settings</q>, then <q>NTLM</q>, then set the
  123. value of NTLM to 1.</p>
  124. </body>
  125. </html>