📄 ch08_151.htm
字号:
<html><head><title>Net::Cmd (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch08_150.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch08_152.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">8.151. Net::Cmd</h2><p><a name="INDEX-1506" /><a name="INDEX-1507" />The network command class, which isrequired by all of the modules under the libnet umbrella: Net::FTP,Net::SMTP, Net::POP3, etc. In addition, Net::Cmd can be inherited bya subclass of IO::Handle. Unless you are writing a new module thatwill become a part of libnet, Net::Cmd probablydoesn't have any servicable parts thatyou'd be interested in, since these parts arealready implemented in the underlying modules. This module is part ofthe core Perl distribution starting with Perl 5.8.</p><p>Net::Cmd implements the following methods, which provide an interfaceto the Net::Cmd object.</p><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>code</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>code()</pre><p>Returns the three-digit code from the last command. If the lastcommand is still pending, <tt class="literal">code</tt> returns<tt class="literal">0</tt>. </p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>dataend</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>dataend()</pre><p>Stops sending data to the remote server and ensures that a final CRLFhas been sent.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>datasend</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>datasend(<em class="replaceable">data</em>)</pre><p>Sends data to the remote server, converting LF to CRLF.<em class="replaceable"><tt>data</tt></em> can be an array or reference to anarray.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>debug</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>debug(<em class="replaceable">level</em>)</pre><p>Sets the debug level for the object. If you do not specify a value,then no debugging information will be provided. If you specify<tt class="literal">undef</tt> as the value, then the debug level will bedetermined by the debug level of the class.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>message</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>message()</pre><p>Returns a text message from the last command.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>ok</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>ok()</pre><p>Returns nonzero if the last code value was greater than 0 and lessthan 400.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>status</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>status()</pre><p>Returns the current status code and, if pending, returns<tt class="literal">CMD_PENDING</tt>.</p></div><p>Net::Cmd implements the following class methods, which you shouldprobably never touch at a user level.</p><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>command</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>command(<em class="replaceable">command</em>, [, <em class="replaceable">args</em>, ...])</pre><p>Sends a command to the remote server. Returns<tt class="literal">undef</tt> on failure.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>debug_print</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>debug_print(<em class="replaceable">dir</em>, <em class="replaceable">text</em>)</pre><p>Outputs debugging information. <em class="replaceable">dir</em>represents data sent to the server, and<em class="replaceable"><tt>text</tt></em> is the text that is sent.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>debug_text</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>debug_text(<em class="replaceable">text</em>)</pre><p>Prints debugging information.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>getline</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>getline()</pre><p>Retrieves one line, delimited by CRLF, from the remote server.Returns <tt class="literal">undef</tt> on failure.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>parse_response</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>parse_response(<em class="replaceable">text</em>)</pre><p>Returns an array of two values: the three-digit status code and aflag that is true when this is part of a multiline response. Calledby <tt class="literal">response</tt> as a method with one argument.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>read_until_dot</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>read_until_dot()</pre><p>Reads data from the remote server until a line consisting of a single<tt class="literal">.</tt> is encountered. If the line matches<tt class="literal">..</tt>, one of the dots will be removed. Returns areference to a list containing the lines or <tt class="literal">undef</tt>on failure.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>response</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>response()</pre><p>Obtains a response from the server. On success, it returns the statuscode, or <tt class="literal">undef</tt> on failure.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>tied_fh</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>tied_fh()</pre><p>Returns a filehandle tied to the Net::Cmd object. After you send acommand, you can read from this filehandle with<tt class="literal">read()</tt> or from <tt class="literal"><></tt>.Returns end-of-file when the final dot is encountered.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>ungetline</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>ungetline(<em class="replaceable">text</em>)</pre><p>Pushes back a line of text from the server.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>unsupported</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>unsupported()</pre><p>Sets the status code to <tt class="literal">580</tt> and the response to<tt class="literal">Unsupported command</tt>. Returns <tt class="literal">0</tt>.</p></div><p>Net::Cmd exports <tt class="literal">CMD_INFO</tt>,<tt class="literal">CMD_OK</tt>, <tt class="literal">CMD_MORE</tt>,<tt class="literal">CMD_REJECT</tt>, <tt class="literal">CMD_ERROR</tt>, and<tt class="literal">CMD_PENDING</tt>.</p><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch08_150.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch08_152.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">8.150. NDBM_File</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">8.152. Net::Config</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -