📄 ch22_07.htm
字号:
size => <em class="replaceable"><tt>size</tt></em>attr => <em class="replaceable"><tt>attributes</tt></em>ctime => <em class="replaceable"><tt>creation time</tt></em>atime => <em class="replaceable"><tt>last access time</tt></em>mtime => <em class="replaceable"><tt>last modified time</tt></em></pre></blockquote><p>All times are reported as strings of the following format: second,hour, minute, day, month, year. For example:</p><blockquote><pre class="code">$file->{'mtime'} == "0,10,58,9,12,1996"# Stands for 09 Dec 1996 at 10:58:00</pre></blockquote></dd></dl></div><a name="INDEX-3278" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Mkdir</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>$<em class="replaceable">FTP</em>->Mkdir(<em class="replaceable">name</em>)$<em class="replaceable">FTP</em>->Md(<em class="replaceable">name</em>)</pre></td><td align="right" /></tr></table><p><p><a name="INDEX-3278" />Creates the directory<em class="replaceable"><tt>name</tt></em> on the FTP remote host. Returns<tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3279" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Mode</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">FTP</em>->Mode([<em class="replaceable">mode</em>])</pre><p><a name="INDEX-3279" />If called with no arguments, returnsthe current transfer mode for this FTP session(<tt class="literal">asc</tt> for ASCII or <tt class="literal">bin</tt> forbinary). The <em class="replaceable"><tt>mode</tt></em> argument can be<tt class="literal">asc</tt> or <tt class="literal">bin</tt>, in which case theappropriate transfer mode is selected. Returns<tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3280" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Pasv</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">FTP</em>->Pasv([<em class="replaceable">mode</em>])</pre><p><a name="INDEX-3280" />If called with no arguments,returns <tt class="literal">1</tt> if the current FTP session has passivetransfer mode enabled; <tt class="literal">0</tt> if not. You can call itwith a <em class="replaceable"><tt>mode</tt></em> parameter(<tt class="literal">0</tt>/<tt class="literal">1</tt>) only as a method of aInternet object, in which case it will set the default value for thenext FTP object you create (i.e., set it before, because youcan't change this value once you open the FTPsession).</p></div><a name="INDEX-3281" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Put</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">FTP</em>->Put(<em class="replaceable">file</em>, [<em class="replaceable">remote</em>, <em class="replaceable">context</em>]<em class="replaceable">)</em></pre><p><a name="INDEX-3281" />Uploads the local<em class="replaceable">file</em> to the FTP server, saving it underthe name <em class="replaceable"><tt>remote</tt></em>, which, if omitted, is thesame name as <em class="replaceable"><tt>file</tt></em>. Returns<tt class="literal">undef</tt> on error. <em class="replaceable"><tt>context</tt></em>is a number to identify this operation if it is asynchronous. See<tt class="literal">SetStatusCallback</tt> and<tt class="literal">GetStatusCallback</tt> for more information onasynchronous operations.</p></div><a name="INDEX-3282" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Pwd</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">FTP</em>->Pwd( )</pre><p><a name="INDEX-3282" />Returns the currentdirectory on the FTP server, or <tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3283" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Rename</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>$<em class="replaceable">FTP</em>->Rename(<em class="replaceable">oldfile</em>, <em class="replaceable">newfile</em><em class="replaceable">)</em>$<em class="replaceable">FTP</em>->Ren(<em class="replaceable">oldfile</em>, <em class="replaceable">newfile</em>)</pre></td><td align="right" /></tr></table><p><p><a name="INDEX-3283" />Renames a file on the FTPremote host. Returns <tt class="literal">undef</tt> on error.</p></div><a name="INDEX-3284" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Rmdir</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>$<em class="replaceable">FTP</em>->Rmdir(<em class="replaceable">name</em>)$<em class="replaceable">FTP</em>->Rd(<em class="replaceable">name</em>)</pre></td><td align="right" /></tr></table><p><p><a name="INDEX-3284" />Removes the directory<em class="replaceable"><tt>name</tt></em> on the FTP remote host. Returns<tt class="literal">undef</tt> on error.</p></div></div><a name="perlnut2-CHP-22-SECT-7.3" /><div class="sect2"><h3 class="sect2">22.7.3. HTTP Functions</h3><p><a name="INDEX-3285" />The methods described in this section areused to create and control an HTTP session. Open an HTTP sessionusing the <tt class="literal">HTTP</tt> method on an Internet connectionobject:</p><blockquote><pre class="code">use Win32::Internet;$inet = new Win32::Internet( );$inet->HTTP($http, "hostname", "username", "password");</pre></blockquote><p>This opens the session and creates the HTTP session object<tt class="literal">$http</tt>. The following methods can be used on HTTPsession objects.</p><a name="INDEX-3286" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>AddHeader</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">request</em>->AddHeader(<em class="replaceable">header</em>, [<em class="replaceable">flags</em>])</pre><p><a name="INDEX-3286" />Adds HTTP request headers to an HTTPrequest object created with <tt class="literal">OpenRequest</tt>. For thepossible values of <em class="replaceable"><tt>flags</tt></em>, refer to theMicrosoft Win32 Internet Functions documentation.</p></div><a name="INDEX-3287" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>OpenRequest</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>$<em class="replaceable">http</em>->OpenRequest(<em class="replaceable">requestobject</em>, [<em class="replaceable">path</em>, <em class="replaceable">method</em>, <em class="replaceable">version</em>, <em class="replaceable">referer</em>, <em class="replaceable">accept</em>, <em class="replaceable">flags</em>, <em class="replaceable">context</em>])$<em class="replaceable"><tt>http</em>->OpenRequest($<em class="replaceable">requestobject</em>, <em class="replaceable">hashref</tt></em>)</pre></td><td align="right" /></tr></table><p><p><a name="INDEX-3287" />Opens an HTTP request andsaves it as<tt class="literal">$</tt><em class="replaceable"><tt>requestobject</tt></em>. Returns<tt class="literal">undef</tt> on error, or a number if the connection wassuccessful. You can then use one of the <tt class="literal">AddHeader</tt>,<tt class="literal">SendRequest</tt>, <tt class="literal">QueryInfo</tt>,<tt class="literal">QueryDataAvailable</tt>, and<tt class="literal">ReadFile</tt> methods on the newly created<em class="replaceable"><tt>requestobject</tt></em>. The optional parameters andtheir values are:</p><dl><dt><i><em class="replaceable"><tt>path</tt></em> </i></dt><dd>The object to request. This is generally a filename, an executablemodule, etc. The default is <tt class="literal">/</tt>.</p></dd><dt><i><em class="replaceable"><tt>method</tt></em></i></dt><dd>The method to use, which can be GET, POST, HEAD, or PUT. Default isGET.</p></dd><dt><i><em class="replaceable"><tt>version</tt></em></i></dt><dd>The HTTP version. Default is <tt class="literal">HTTP/1.0</tt>.</p></dd><dt><i><em class="replaceable"><tt>referer</tt></em></i></dt><dd>The URL of the document from which the URL in the request wasobtained.</p></dd><dt><i><em class="replaceable"><tt>accept</tt></em></i></dt><dd>The content types accepted. They must be separated by a<tt class="literal">\0</tt> (ASCII zero). Default types are <tt class="literal">text/*image/gif image/jpeg</tt>.</p></dd><dt><i><em class="replaceable"><tt>flags</tt></em></i></dt><dd>Additional flags affecting the behavior of the function.</p></dd><dt><i><em class="replaceable"><tt>context</tt></em></i></dt><dd>A number to identify this operation if it is asynchronous. See<tt class="literal">SetStatusCallback</tt> and<tt class="literal">GetStatusCallback</tt> for more information onasynchronous operations.</p></dd></dl><p>A reference to a hash containing the previous list of parameters canalso be supplied to this method:</p><blockquote><pre class="code">%hash=( "path" => "path", "method" => "method", "version" => "version", "referer" => "referer", "accept" => "accept", "flags" => flags, "context" => context,);</pre></blockquote></div><a name="INDEX-3288" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>QueryInfo</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">request</em>->QueryInfo(<em class="replaceable">header</em>, [<em class="replaceable">flags</em>])</pre><p><a name="INDEX-3288" />Queries information about anHTTP request object(<tt class="literal">$</tt><em class="replaceable"><tt>request</tt></em>) created with<tt class="literal">OpenRequest</tt>. You can specify a header (forexample, <tt class="literal">Content-type</tt>) and/or one or more flags.If you don't specify<em class="replaceable"><tt>flags</tt></em>,<tt class="literal">HTTP_QUERY_CUSTOM</tt> will be used by default; thismeans that the header should contain a valid HTTP header name. Forthe possible values of <em class="replaceable"><tt>flags</tt></em>, refer to theMicrosoft Win32 Internet Functions documentation.</p></div><a name="INDEX-3289" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>Request</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>$<em class="replaceable">http</em>->Request([<em class="replaceable">path</em>, <em class="replaceable">method</em>, <em class="replaceable">version</em>, <em class="replaceable">referer</em>, <em class="replaceable">accept</em>, <em class="replaceable">flags</em>])$<em class="replaceable">http</em>->Request(<em class="replaceable">hashref</em>)</pre></td><td align="right" /></tr></table><p><p><a name="INDEX-3289" />Performs an HTTP request andreturns an array containing the status code, the headers, and thecontent of the file. It is a one-step procedure that executes<tt class="literal">OpenRequest</tt>, <tt class="literal">SendRequest</tt>,<tt class="literal">QueryInfo</tt>, <tt class="literal">ReadFile</tt>, andfinally, <tt class="literal">Close</tt>. For a description of theparameters, see <tt class="literal">OpenRequest</tt>.</p></div><a name="INDEX-3290" /><a name="INDEX-3291" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>SendRequest</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">request</em>->SendRequest([<em class="replaceable">postdata</em>])</pre><p><a name="INDEX-3290" />Sends an HTTP request to thedestination server. <em class="replaceable"><tt>postdata</tt></em> contains anyoptional data to send immediately after the request header; this isgenerally used for POST or PUT requests. Your request object mustcontain the following content header for post data to be processed.You can add the header with <tt class="literal">AddHeader</tt>:</p><a name="INDEX-3291" /><blockquote><pre class="code">...$request->AddHeader("Content-Type: application/x-www-form-urlencoded");$request->SendRequest("key1=value1&key2=value2&key3=value3");</pre></blockquote></div></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch22_06.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="ch22_08.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">22.6. Win32::FileSecurity</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">22.8. Win32::IPC</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 + -