.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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 "2021-09-24" "perl v5.32.1" "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. .SH "USER METHODS" .IX Header "USER METHODS" These methods provide a user interface to the \f(CW\*(C`Net::Cmd\*(C'\fR object. .IP "debug ( \s-1VALUE\s0 )" 4 .IX Item "debug ( VALUE )" Set the level of debug information for this object. If \f(CW\*(C`VALUE\*(C'\fR is not given then the current state is returned. Otherwise the state is changed to \&\f(CW\*(C`VALUE\*(C'\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\*(C`VALUE\*(C'\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. .IP "message ()" 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.) .IP "code ()" 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.) .IP "ok ()" 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. .IP "status ()" 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. .IP "datasend ( \s-1DATA\s0 )" 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\*(C`DATA\*(C'\fR may be an array or a reference to an array. The \f(CW\*(C`DATA\*(C'\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. .IP "dataend ()" 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 .SH "CLASS METHODS" .IX Header "CLASS 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 .IP "debug_print ( \s-1DIR, TEXT\s0 )" 4 .IX Item "debug_print ( DIR, TEXT )" Print debugging information. \f(CW\*(C`DIR\*(C'\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 .IP "debug_text ( \s-1DIR, TEXT\s0 )" 4 .IX Item "debug_text ( DIR, TEXT )" This method is called to print debugging information. \s-1TEXT\s0 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. .IP "command ( \s-1CMD\s0 [, \s-1ARGS, ...\s0 ])" 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. .IP "unsupported ()" 4 .IX Item "unsupported ()" Sets the status code to 580 and the response text to 'Unsupported command'. Returns zero. .IP "response ()" 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. .IP "parse_response ( \s-1TEXT\s0 )" 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. .IP "getline ()" 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. .IP "ungetline ( \s-1TEXT\s0 )" 4 .IX Item "ungetline ( TEXT )" Unget a line of text from the server. .IP "rawdatasend ( \s-1DATA\s0 )" 4 .IX Item "rawdatasend ( DATA )" Send data to the remote server without performing any conversions. \f(CW\*(C`DATA\*(C'\fR is a scalar. As with \f(CW\*(C`datasend()\*(C'\fR, the \f(CW\*(C`DATA\*(C'\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. .IP "read_until_dot ()" 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. .IP "tied_fh ()" 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. .SH "PSEUDO RESPONSES" .IX Header "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" \&\f(CW\*(C`Net::Cmd\*(C'\fR exports six subroutines, five of these, \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 and \f(CW\*(C`CMD_ERROR\*(C'\fR, correspond to possible results of \f(CW\*(C`response\*(C'\fR and \f(CW\*(C`status\*(C'\fR. The sixth is \f(CW\*(C`CMD_PENDING\*(C'\fR. .SH "AUTHOR" .IX Header "AUTHOR" Graham Barr <\fIgbarr@pobox.com\fR>. .PP Steve Hay <\fIshay@cpan.org\fR> 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 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.