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