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