1Net::Cmd(3)           User Contributed Perl Documentation          Net::Cmd(3)
2
3
4

NAME

6       Net::Cmd - Network Command class (as used by FTP, SMTP etc)
7

SYNOPSIS

9           use Net::Cmd;
10
11           @ISA = qw(Net::Cmd);
12

DESCRIPTION

14       "Net::Cmd" is a collection of methods that can be inherited by a sub-
15       class of "IO::Socket::INET". These methods implement the functionality
16       required for a command based protocol, for example FTP and SMTP.
17
18       If your sub-class does not also derive from "IO::Socket::INET" or
19       similar (e.g.  "IO::Socket::IP", "IO::Socket::INET6" or
20       "IO::Socket::SSL") then you must provide the following methods by other
21       means yourself: close() and timeout().
22
23   Public Methods
24       These methods provide a user interface to the "Net::Cmd" object.
25
26       debug($level)
27           Set the level of debug information for this object. If $level is
28           not given then the current state is returned. Otherwise the state
29           is changed to $level and the previous state returned.
30
31           Different packages may implement different levels of debug but a
32           non-zero value results in copies of all commands and responses also
33           being sent to STDERR.
34
35           If $level is "undef" then the debug level will be set to the
36           default debug level for the class.
37
38           This method can also be called as a static method to set/get the
39           default debug level for a given class.
40
41       message()
42           Returns the text message returned from the last command. In a
43           scalar context it returns a single string, in a list context it
44           will return each line as a separate element. (See "PSEUDO
45           RESPONSES" below.)
46
47       code()
48           Returns the 3-digit code from the last command. If a command is
49           pending then the value 0 is returned. (See "PSEUDO RESPONSES"
50           below.)
51
52       ok()
53           Returns non-zero if the last code value was greater than zero and
54           less than 400. This holds true for most command servers. Servers
55           where this does not hold may override this method.
56
57       status()
58           Returns the most significant digit of the current status code. If a
59           command is pending then "CMD_PENDING" is returned.
60
61       datasend($data)
62           Send data to the remote server, converting LF to CRLF. Any line
63           starting with a '.' will be prefixed with another '.'.  $data may
64           be an array or a reference to an array.  The $data passed in must
65           be encoded by the caller to octets of whatever encoding is
66           required, e.g. by using the Encode module's encode() function.
67
68       dataend()
69           End the sending of data to the remote server. This is done by
70           ensuring that the data already sent ends with CRLF then sending
71           '.CRLF' to end the transmission. Once this data has been sent
72           "dataend" calls "response" and returns true if "response" returns
73           CMD_OK.
74
75   Protected Methods
76       These methods are not intended to be called by the user, but used or
77       over-ridden by a sub-class of "Net::Cmd"
78
79       "debug_print($dir, $text)"
80           Print debugging information. $dir denotes the direction true being
81           data being sent to the server. Calls "debug_text" before printing
82           to STDERR.
83
84       "debug_text($dir, $text)"
85           This method is called to print debugging information. $text is the
86           text being sent. The method should return the text to be printed.
87
88           This is primarily meant for the use of modules such as FTP where
89           passwords are sent, but we do not want to display them in the
90           debugging information.
91
92       "command($cmd[, $args, ... ])"
93           Send a command to the command server. All arguments are first
94           joined with a space character and CRLF is appended, this string is
95           then sent to the command server.
96
97           Returns undef upon failure.
98
99       unsupported()
100           Sets the status code to 580 and the response text to 'Unsupported
101           command'.  Returns zero.
102
103       response()
104           Obtain a response from the server. Upon success the most
105           significant digit of the status code is returned. Upon failure,
106           timeout etc., CMD_ERROR is returned.
107
108       parse_response($text)
109           This method is called by "response" as a method with one argument.
110           It should return an array of 2 values, the 3-digit status code and
111           a flag which is true when this is part of a multi-line response and
112           this line is not the last.
113
114       getline()
115           Retrieve one line, delimited by CRLF, from the remote server.
116           Returns undef upon failure.
117
118           NOTE: If you do use this method for any reason, please remember to
119           add some "debug_print" calls into your method.
120
121       ungetline($text)
122           Unget a line of text from the server.
123
124       rawdatasend($data)
125           Send data to the remote server without performing any conversions.
126           $data is a scalar.  As with datasend(), the $data passed in must be
127           encoded by the caller to octets of whatever encoding is required,
128           e.g. by using the Encode module's encode() function.
129
130       read_until_dot()
131           Read data from the remote server until a line consisting of a
132           single '.'.  Any lines starting with '..' will have one of the '.'s
133           removed.
134
135           Returns a reference to a list containing the lines, or undef upon
136           failure.
137
138       tied_fh()
139           Returns a filehandle tied to the Net::Cmd object.  After issuing a
140           command, you may read from this filehandle using read() or <>.  The
141           filehandle will return EOF when the final dot is encountered.
142           Similarly, you may write to the filehandle in order to send data to
143           the server after issuing a command that expects data to be written.
144
145           See the Net::POP3 and Net::SMTP modules for examples of this.
146
147   Pseudo Responses
148       Normally the values returned by message() and code() are obtained from
149       the remote server, but in a few circumstances, as detailed below,
150       "Net::Cmd" will return values that it sets. You can alter this behavior
151       by overriding DEF_REPLY_CODE() to specify a different default reply
152       code, or overriding one of the specific error handling methods below.
153
154       Initial value
155           Before any command has executed or if an unexpected error occurs
156           code() will return "421" (temporary connection failure) and
157           message() will return undef.
158
159       Connection closed
160           If the underlying "IO::Handle" is closed, or if there are any read
161           or write failures, the file handle will be forced closed, and
162           code() will return "421" (temporary connection failure) and
163           message() will return "[$pkg] Connection closed" (where $pkg is the
164           name of the class that subclassed "Net::Cmd").  The
165           _set_status_closed() method can be overridden to set a different
166           message (by calling set_status()) or otherwise trap this error.
167
168       Timeout
169           If there is a read or write timeout code() will return "421"
170           (temporary connection failure) and message() will return "[$pkg]
171           Timeout" (where $pkg is the name of the class that subclassed
172           "Net::Cmd"). The _set_status_timeout() method can be overridden to
173           set a different message (by calling set_status()) or otherwise trap
174           this error.
175

EXPORTS

177       The following symbols are, or can be, exported by this module:
178
179       Default Exports
180           "CMD_INFO", "CMD_OK", "CMD_MORE", "CMD_REJECT", "CMD_ERROR",
181           "CMD_PENDING".
182
183           (These correspond to possible results of response() and status().)
184
185       Optional Exports
186           None.
187
188       Export Tags
189           None.
190

KNOWN BUGS

192       See <https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet>.
193

AUTHOR

195       Graham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.
196
197       Steve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining
198       libnet as of version 1.22_02.
199
201       Copyright (C) 1995-2006 Graham Barr.  All rights reserved.
202
203       Copyright (C) 2013-2016, 2020, 2022 Steve Hay.  All rights reserved.
204

LICENCE

206       This module is free software; you can redistribute it and/or modify it
207       under the same terms as Perl itself, i.e. under the terms of either the
208       GNU General Public License or the Artistic License, as specified in the
209       LICENCE file.
210

VERSION

212       Version 3.15
213

DATE

215       20 March 2023
216

HISTORY

218       See the Changes file.
219
220
221
222perl v5.38.0                      2023-07-21                       Net::Cmd(3)
Impressum