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

USER METHODS

24       These methods provide a user interface to the "Net::Cmd" object.
25
26       debug ( VALUE )
27           Set the level of debug information for this object. If "VALUE" is
28           not given then the current state is returned. Otherwise the state
29           is changed to "VALUE" 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 "VALUE" 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

CLASS 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
127           must be encoded by the caller to octets of whatever encoding is
128           required, 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

PSEUDO RESPONSES

148       Normally the values returned by "message()" and "code()" are obtained
149       from 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
164           the 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       "Net::Cmd" exports six subroutines, five of these, "CMD_INFO",
178       "CMD_OK", "CMD_MORE", "CMD_REJECT" and "CMD_ERROR", correspond to
179       possible results of "response" and "status". The sixth is
180       "CMD_PENDING".
181

AUTHOR

183       Graham Barr <gbarr@pobox.com>.
184
185       Steve Hay <shay@cpan.org> is now maintaining libnet as of version
186       1.22_02.
187
189       Copyright (C) 1995-2006 Graham Barr.  All rights reserved.
190
191       Copyright (C) 2013-2016 Steve Hay.  All rights reserved.
192

LICENCE

194       This module is free software; you can redistribute it and/or modify it
195       under the same terms as Perl itself, i.e. under the terms of either the
196       GNU General Public License or the Artistic License, as specified in the
197       LICENCE file.
198
199
200
201perl v5.26.3                      2017-11-14                       Net::Cmd(3)
Impressum