1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Net::Cmd 3perl"
.TH Net::Cmd 3perl "2023-11-25" "perl v5.36.0" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Net::Cmd \- Network Command class (as used by FTP, SMTP etc)
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Net::Cmd;
\&
\& @ISA = qw(Net::Cmd);
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\f(CW\*(C`Net::Cmd\*(C'\fR is a collection of methods that can be inherited by a sub-class
of \f(CW\*(C`IO::Socket::INET\*(C'\fR. These methods implement the functionality required for a
command based protocol, for example \s-1FTP\s0 and \s-1SMTP.\s0
.PP
If your sub-class does not also derive from \f(CW\*(C`IO::Socket::INET\*(C'\fR or similar (e.g.
\&\f(CW\*(C`IO::Socket::IP\*(C'\fR, \f(CW\*(C`IO::Socket::INET6\*(C'\fR or \f(CW\*(C`IO::Socket::SSL\*(C'\fR) then you must
provide the following methods by other means yourself: \f(CW\*(C`close()\*(C'\fR and
\&\f(CW\*(C`timeout()\*(C'\fR.
.SS "Public Methods"
.IX Subsection "Public Methods"
These methods provide a user interface to the \f(CW\*(C`Net::Cmd\*(C'\fR object.
.ie n .IP """debug($level)""" 4
.el .IP "\f(CWdebug($level)\fR" 4
.IX Item "debug($level)"
Set the level of debug information for this object. If \f(CW$level\fR is not given
then the current state is returned. Otherwise the state is changed to
\&\f(CW$level\fR and the previous state returned.
.Sp
Different packages
may implement different levels of debug but a non-zero value results in
copies of all commands and responses also being sent to \s-1STDERR.\s0
.Sp
If \f(CW$level\fR is \f(CW\*(C`undef\*(C'\fR then the debug level will be set to the default
debug level for the class.
.Sp
This method can also be called as a \fIstatic\fR method to set/get the default
debug level for a given class.
.ie n .IP """message()""" 4
.el .IP "\f(CWmessage()\fR" 4
.IX Item "message()"
Returns the text message returned from the last command. In a scalar
context it returns a single string, in a list context it will return
each line as a separate element. (See \*(L"\s-1PSEUDO RESPONSES\*(R"\s0 below.)
.ie n .IP """code()""" 4
.el .IP "\f(CWcode()\fR" 4
.IX Item "code()"
Returns the 3\-digit code from the last command. If a command is pending
then the value 0 is returned. (See \*(L"\s-1PSEUDO RESPONSES\*(R"\s0 below.)
.ie n .IP """ok()""" 4
.el .IP "\f(CWok()\fR" 4
.IX Item "ok()"
Returns non-zero if the last code value was greater than zero and
less than 400. This holds true for most command servers. Servers
where this does not hold may override this method.
.ie n .IP """status()""" 4
.el .IP "\f(CWstatus()\fR" 4
.IX Item "status()"
Returns the most significant digit of the current status code. If a command
is pending then \f(CW\*(C`CMD_PENDING\*(C'\fR is returned.
.ie n .IP """datasend($data)""" 4
.el .IP "\f(CWdatasend($data)\fR" 4
.IX Item "datasend($data)"
Send data to the remote server, converting \s-1LF\s0 to \s-1CRLF.\s0 Any line starting
with a '.' will be prefixed with another '.'.
\&\f(CW$data\fR may be an array or a reference to an array.
The \f(CW$data\fR passed in must be encoded by the caller to octets of whatever
encoding is required, e.g. by using the Encode module's \f(CW\*(C`encode()\*(C'\fR function.
.ie n .IP """dataend()""" 4
.el .IP "\f(CWdataend()\fR" 4
.IX Item "dataend()"
End the sending of data to the remote server. This is done by ensuring that
the data already sent ends with \s-1CRLF\s0 then sending '.CRLF' to end the
transmission. Once this data has been sent \f(CW\*(C`dataend\*(C'\fR calls \f(CW\*(C`response\*(C'\fR and
returns true if \f(CW\*(C`response\*(C'\fR returns \s-1CMD_OK.\s0
.SS "Protected Methods"
.IX Subsection "Protected Methods"
These methods are not intended to be called by the user, but used or
over-ridden by a sub-class of \f(CW\*(C`Net::Cmd\*(C'\fR
.ie n .IP """debug_print($dir, $text)""" 4
.el .IP "\f(CWdebug_print($dir, $text)\fR" 4
.IX Item "debug_print($dir, $text)"
Print debugging information. \f(CW$dir\fR denotes the direction \fItrue\fR being
data being sent to the server. Calls \f(CW\*(C`debug_text\*(C'\fR before printing to
\&\s-1STDERR.\s0
.ie n .IP """debug_text($dir, $text)""" 4
.el .IP "\f(CWdebug_text($dir, $text)\fR" 4
.IX Item "debug_text($dir, $text)"
This method is called to print debugging information. \f(CW$text\fR is
the text being sent. The method should return the text to be printed.
.Sp
This is primarily meant for the use of modules such as \s-1FTP\s0 where passwords
are sent, but we do not want to display them in the debugging information.
.ie n .IP """command($cmd[, $args, ... ])""" 4
.el .IP "\f(CWcommand($cmd[, $args, ... ])\fR" 4
.IX Item "command($cmd[, $args, ... ])"
Send a command to the command server. All arguments are first joined with
a space character and \s-1CRLF\s0 is appended, this string is then sent to the
command server.
.Sp
Returns undef upon failure.
.ie n .IP """unsupported()""" 4
.el .IP "\f(CWunsupported()\fR" 4
.IX Item "unsupported()"
Sets the status code to 580 and the response text to 'Unsupported command'.
Returns zero.
.ie n .IP """response()""" 4
.el .IP "\f(CWresponse()\fR" 4
.IX Item "response()"
Obtain a response from the server. Upon success the most significant digit
of the status code is returned. Upon failure, timeout etc., \fI\s-1CMD_ERROR\s0\fR is
returned.
.ie n .IP """parse_response($text)""" 4
.el .IP "\f(CWparse_response($text)\fR" 4
.IX Item "parse_response($text)"
This method is called by \f(CW\*(C`response\*(C'\fR as a method with one argument. It should
return an array of 2 values, the 3\-digit status code and a flag which is true
when this is part of a multi-line response and this line is not the last.
.ie n .IP """getline()""" 4
.el .IP "\f(CWgetline()\fR" 4
.IX Item "getline()"
Retrieve one line, delimited by \s-1CRLF,\s0 from the remote server. Returns \fIundef\fR
upon failure.
.Sp
\&\fB\s-1NOTE\s0\fR: If you do use this method for any reason, please remember to add
some \f(CW\*(C`debug_print\*(C'\fR calls into your method.
.ie n .IP """ungetline($text)""" 4
.el .IP "\f(CWungetline($text)\fR" 4
.IX Item "ungetline($text)"
Unget a line of text from the server.
.ie n .IP """rawdatasend($data)""" 4
.el .IP "\f(CWrawdatasend($data)\fR" 4
.IX Item "rawdatasend($data)"
Send data to the remote server without performing any conversions. \f(CW$data\fR
is a scalar.
As with \f(CW\*(C`datasend()\*(C'\fR, the \f(CW$data\fR passed in must be encoded by the caller
to octets of whatever encoding is required, e.g. by using the Encode module's
\&\f(CW\*(C`encode()\*(C'\fR function.
.ie n .IP """read_until_dot()""" 4
.el .IP "\f(CWread_until_dot()\fR" 4
.IX Item "read_until_dot()"
Read data from the remote server until a line consisting of a single '.'.
Any lines starting with '..' will have one of the '.'s removed.
.Sp
Returns a reference to a list containing the lines, or \fIundef\fR upon failure.
.ie n .IP """tied_fh()""" 4
.el .IP "\f(CWtied_fh()\fR" 4
.IX Item "tied_fh()"
Returns a filehandle tied to the Net::Cmd object. After issuing a
command, you may read from this filehandle using \fBread()\fR or <>. The
filehandle will return \s-1EOF\s0 when the final dot is encountered.
Similarly, you may write to the filehandle in order to send data to
the server after issuing a command that expects data to be written.
.Sp
See the Net::POP3 and Net::SMTP modules for examples of this.
.SS "Pseudo Responses"
.IX Subsection "Pseudo Responses"
Normally the values returned by \f(CW\*(C`message()\*(C'\fR and \f(CW\*(C`code()\*(C'\fR are
obtained from the remote server, but in a few circumstances, as
detailed below, \f(CW\*(C`Net::Cmd\*(C'\fR will return values that it sets. You
can alter this behavior by overriding \s-1\fBDEF_REPLY_CODE\s0()\fR to specify
a different default reply code, or overriding one of the specific
error handling methods below.
.IP "Initial value" 4
.IX Item "Initial value"
Before any command has executed or if an unexpected error occurs
\&\f(CW\*(C`code()\*(C'\fR will return \*(L"421\*(R" (temporary connection failure) and
\&\f(CW\*(C`message()\*(C'\fR will return undef.
.IP "Connection closed" 4
.IX Item "Connection closed"
If the underlying \f(CW\*(C`IO::Handle\*(C'\fR is closed, or if there are
any read or write failures, the file handle will be forced closed,
and \f(CW\*(C`code()\*(C'\fR will return \*(L"421\*(R" (temporary connection failure)
and \f(CW\*(C`message()\*(C'\fR will return \*(L"[$pkg] Connection closed\*(R"
(where \f(CW$pkg\fR is the name of the class that subclassed \f(CW\*(C`Net::Cmd\*(C'\fR).
The \fB_set_status_closed()\fR method can be overridden to set a different
message (by calling \fBset_status()\fR) or otherwise trap this error.
.IP "Timeout" 4
.IX Item "Timeout"
If there is a read or write timeout \f(CW\*(C`code()\*(C'\fR will return \*(L"421\*(R"
(temporary connection failure) and \f(CW\*(C`message()\*(C'\fR will return
\&\*(L"[$pkg] Timeout\*(R" (where \f(CW$pkg\fR is the name of the class
that subclassed \f(CW\*(C`Net::Cmd\*(C'\fR). The \fB_set_status_timeout()\fR method
can be overridden to set a different message (by calling \fBset_status()\fR)
or otherwise trap this error.
.SH "EXPORTS"
.IX Header "EXPORTS"
The following symbols are, or can be, exported by this module:
.IP "Default Exports" 4
.IX Item "Default Exports"
\&\f(CW\*(C`CMD_INFO\*(C'\fR,
\&\f(CW\*(C`CMD_OK\*(C'\fR,
\&\f(CW\*(C`CMD_MORE\*(C'\fR,
\&\f(CW\*(C`CMD_REJECT\*(C'\fR,
\&\f(CW\*(C`CMD_ERROR\*(C'\fR,
\&\f(CW\*(C`CMD_PENDING\*(C'\fR.
.Sp
(These correspond to possible results of \f(CW\*(C`response()\*(C'\fR and \f(CW\*(C`status()\*(C'\fR.)
.IP "Optional Exports" 4
.IX Item "Optional Exports"
\&\fINone\fR.
.IP "Export Tags" 4
.IX Item "Export Tags"
\&\fINone\fR.
.SH "KNOWN BUGS"
.IX Header "KNOWN BUGS"
See <https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet>.
.SH "AUTHOR"
.IX Header "AUTHOR"
Graham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.
.PP
Steve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining
libnet as of version 1.22_02.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (C) 1995\-2006 Graham Barr. All rights reserved.
.PP
Copyright (C) 2013\-2016, 2020 Steve Hay. All rights reserved.
.SH "LICENCE"
.IX Header "LICENCE"
This module is free software; you can redistribute it and/or modify it under the
same terms as Perl itself, i.e. under the terms of either the \s-1GNU\s0 General Public
License or the Artistic License, as specified in the \fI\s-1LICENCE\s0\fR file.
.SH "VERSION"
.IX Header "VERSION"
Version 3.14
.SH "DATE"
.IX Header "DATE"
23 Dec 2020
.SH "HISTORY"
.IX Header "HISTORY"
See the \fIChanges\fR file.
|