Net::Cmd(3pm)
π Net::Cmd(3pm) β bestie edition π
okay so this is the Net::Cmd(3pm) page from the Perl Programmers Reference Guide, and it is literally the Network Command class (as used by FTP, SMTP etc). No cap, it's the command-protocol bestie you inherit from when you're building FTP/SMTP-adjacent stuff. π
β¨ NAME β¨
Net::Cmd β Network Command class (as used by FTP, SMTP etc)
π°οΈ SYNOPSIS π°οΈ
use Net::Cmd;
@ISA = qw(Net::Cmd);
πΈ DESCRIPTION πΈ
Net::Cmd is a collection of methods that can be inherited by a sub-class of IO::Socket::INET. These methods implement the functionality required for a command based protocol, for example FTP and SMTP. periodt, that's the whole vibe. β¨
If your sub-class does not also derive from IO::Socket::INET or similar (e.g. IO::Socket::IP, IO::Socket::INET6 or IO::Socket::SSL) then you must provide the following methods by other means yourself: close() and timeout(). iykyk β those two are on you, bestie. π«Ά
π«Ά Public Methods π«Ά
These methods provide a user interface to the Net::Cmd object. main character energy, honestly.
debug($level)β Set the level of debug information for this object. If$levelis not given then the current state is returned. Otherwise the state is changed to$leveland the previous state returned. Different packages may implement different levels of debug but a non-zero value results in copies of all commands and responses also being sent toSTDERR. If$levelisundefthen the debug level will be set to the default debug level for the class. This method can also be called as a static method to set/get the default debug level for a given class. π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 PSEUDO RESPONSES below.) π¦code()β Returns the 3-digit code from the last command. If a command is pending then the value0is returned. (See PSEUDO RESPONSES below.) π₯ok()β Returns non-zero if the last code value was greater than zero and less than400. This holds true for most command servers. Servers where this does not hold may override this method. βstatus()β Returns the most significant digit of the current status code. If a command is pending thenCMD_PENDINGis returned. πdatasend($data)β Send data to the remote server, convertingLFtoCRLF. Any line starting with a'.'will be prefixed with another'.'.$datamay be an array or a reference to an array. The$datapassed in must be encoded by the caller to octets of whatever encoding is required, e.g. by using the Encode module'sencode()function. πdataend()β End the sending of data to the remote server. This is done by ensuring that the data already sent ends withCRLFthen sending'.CRLF'to end the transmission. Once this data has been sentdataendcallsresponseand returns true ifresponsereturnsCMD_OK. π
π‘οΈ Protected Methods π‘οΈ
These methods are not intended to be called by the user, but used or over-ridden by a sub-class of Net::Cmd. behind-the-scenes icons only. π
debug_print($dir, $text)β Print debugging information.$dirdenotes the direction, true being data being sent to the server. Callsdebug_textbefore printing toSTDERR. π§debug_text($dir, $text)β This method is called to print debugging information.$textis the text being sent. The method should return the text to be printed. This is primarily meant for the use of modules such as FTP where passwords are sent, but we do not want to display them in the debugging information. πcommand($cmd[, $args, ... ])β Send a command to the command server. All arguments are first joined with a space character andCRLFis appended, this string is then sent to the command server. Returnsundefupon failure. πunsupported()β Sets the status code to580and the response text to'Unsupported command'. Returns zero. πresponse()β Obtain a response from the server. Upon success the most significant digit of the status code is returned. Upon failure, timeout etc.,CMD_ERRORis returned. βparse_response($text)β This method is called byresponseas 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. πgetline()β Retrieve one line, delimited byCRLF, from the remote server. Returnsundefupon failure. π
β οΈ NOTE: If you do use this method for any reason, please remember to add some debug_print calls into your method. π«Ά
ungetline($text)β Unget a line of text from the server. πrawdatasend($data)β Send data to the remote server without performing any conversions.$datais a scalar. As withdatasend(), the$datapassed in must be encoded by the caller to octets of whatever encoding is required, e.g. by using the Encode module'sencode()function. π₯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. Returns a reference to a list containing the lines, orundefupon failure. π¦tied_fh()β Returns a filehandle tied to theNet::Cmdobject. After issuing a command, you may read from this filehandle usingread()or<>. The filehandle will returnEOFwhen 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. See theNet::POP3andNet::SMTPmodules for examples of this. π
π Pseudo Responses π
Normally the values returned by message() and code() are obtained from the remote server, but in a few circumstances, as detailed below, Net::Cmd will return values that it sets. You can alter this behavior by overriding DEF_REPLY_CODE() to specify a different default reply code, or overriding one of the specific error handling methods below. plot twist energy. π
Initial value
Before any command has executed or if an unexpected error occurs code() will return 421 (temporary connection failure) and message() will return undef. π«
Connection closed
If the underlying IO::Handle is closed, or if there are any read or write failures, the file handle will be forced closed, and code() will return 421 (temporary connection failure) and message() will return "[$pkg] Connection closed" (where $pkg is the name of the class that subclassed Net::Cmd). The _set_status_closed() method can be overridden to set a different message (by calling set_status()) or otherwise trap this error. πͺπ¨
Timeout
If there is a read or write timeout code() will return 421 (temporary connection failure) and message() will return "[$pkg] Timeout" (where $pkg is the name of the class that subclassed Net::Cmd). The _set_status_timeout() method can be overridden to set a different message (by calling set_status()) or otherwise trap this error. β°π
π EXPORTS π
The following symbols are, or can be, exported by this module:
Default Exports
CMD_INFO,CMD_OK,CMD_MORE,CMD_REJECT,CMD_ERROR,CMD_PENDING. π
(These correspond to possible results of response() and status().) β¨
Optional Exports
None. nothing extra, bestie. π ββοΈ
Export Tags
None. π
π KNOWN BUGS π
See https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet. π
π AUTHOR π
Graham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.
Steve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining libnet as of version 1.22_02. π
Β©οΈ COPYRIGHT Β©οΈ
Copyright (C) 1995-2006 Graham Barr. All rights reserved.
Copyright (C) 2013-2016, 2020, 2022 Steve Hay. All rights reserved.
π 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 GNU General Public License or the Artistic License, as specified in the LICENCE file. legal slay π
π·οΈ VERSION π·οΈ
Version 3.15
π DATE π
20 March 2023
π HISTORY π
See the Changes file. π
okay that's the whole page, bestie π β footer vibes: perl v5.42.3 Β· 2026-11-03 Β· Net::Cmd(3pm). Slay. π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms