⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18_01.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>FTP (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 &amp; 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="ch17_03.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="ch18_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h1 class="chapter">Chapter 18. FTP</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4>  <p> <a href="#perlnut2-CHP-18-SECT-1">The FTP Protocol</a><br /><a href="ch18_02.htm">Net::FTP</a><br /><a href="ch18_03.htm">FTP Configuration with Net::Netrc</a><br /></p></div><p>The File Transfer Protocol (FTP) is a popular means of transferringfiles between <a name="INDEX-2283" /></a>computers. FTP communication followsthe client/server model: the client initiates a conversation bysending commands, and the server responds with messages and statuscodes, as well as by sending or receiving files. This chapterdiscusses two FTP-related modules included in the<em class="emphasis">libnet</em> distribution: Net::FTP, which provides anumber of wrapper functions for implementing the client side of FTP,and Net::Netrc, which provides an interface for getting informationfrom a <em class="emphasis">.netrc</em> file.</p><p>The FTP protocol permits two-way file transactions, in which filescan be sent to or taken from an FTP server. These transactionsinvolve the local filesystem (on the client side) and the remotefilesystem (on the server side). When a file is transferred betweenthe local and remote systems, its filename on the destination systemis the same as on the source system, unless you specify a newfilename.</p><p>The FTP protocol also lists the types of files that can betransferred. These types define (among many other things) howend-of-line characters are handled for different types of files.</p><div class="sect1"><a name="perlnut2-CHP-18-SECT-1" /></a><h2 class="sect1">18.1. The FTP Protocol</h2><p>When a server accepts FTP requests, it opens a port (generally port21) for incoming connections and authenticates clients based onaccount or anonymous privileges. A user may log in with a legitimateaccount on that machine, provide her own password, and access anyfile she normally has access to under the Unixshell<a name="INDEX-2284" /></a>. Manyservers also allow "anonymous" FTP,in which users log in with the name"anonymous" and use their emailaddress as the password. They are then granted restricted access to alimited portion of the filesystem.</p><p>The FTP commands defined in RFC 959 are listed in the following table:</p><a name="ch18-2-fm2xml" /></a><table border="1" cellpadding="3"><tr><th><p>Command</p></th><th><p>Meaning</p></th></tr><tr><td><p>ABOR</p></td><td><p>Abort previous FTP command.</p></td></tr><tr><td><p>ACCT</p></td><td><p>Specify the user's account.</p></td></tr><tr><td><p>ALLO</p></td><td><p>Tell server to allocate additional storage for new file.</p></td></tr><tr><td><p>APPE</p></td><td><p>Tell server to append to an existing file.</p></td></tr><tr><td><p>CDUP</p></td><td><p>Change to parent directory.</p></td></tr><tr><td><p>CWD</p></td><td><p>Change directory.</p></td></tr><tr><td><p>DELE</p></td><td><p>Delete a file.</p></td></tr><tr><td><p>HELP</p></td><td><p>Get help.</p></td></tr><tr><td><p>LIST</p></td><td><p>List files for display.</p></td></tr><tr><td><p>MKD</p></td><td><p>Make a directory.</p></td></tr><tr><td><p>MODE</p></td><td><p>Specify the data transfer mode.</p></td></tr><tr><td><p>NLST</p></td><td><p>List files for additional processing.</p></td></tr><tr><td><p>NOOP</p></td><td><p>No-op.</p></td></tr><tr><td><p>PASS</p></td><td><p>Specify the user's password.</p></td></tr><tr><td><p>PASV</p></td><td><p>Tell server to go into "passive"mode.</p></td></tr><tr><td><p>PORT</p></td><td><p>Specify data port for connection.</p></td></tr><tr><td><p>PWD</p></td><td><p>Print working directory.</p></td></tr><tr><td><p>QUIT</p></td><td><p>Close connection.</p></td></tr><tr><td><p>REIN</p></td><td><p>Reinitialize connection.</p></td></tr><tr><td><p>REST</p></td><td><p>Restart a file transfer.</p></td></tr><tr><td><p>RETR</p></td><td><p>Retrieve a file.</p></td></tr><tr><td><p>RMD</p></td><td><p>Remove a directory.</p></td></tr><tr><td><p>RNFR</p></td><td><p>Specify pathname of file to be renamed.</p></td></tr><tr><td><p>RNTO</p></td><td><p>Specify new name of file being renamed.</p></td></tr><tr><td><p>SITE</p></td><td><p>Provide additional site-specific services.</p></td></tr><tr><td><p>SMNT</p></td><td><p>Mount a different filesystem.</p></td></tr><tr><td><p>STAT</p></td><td><p>Get status.</p></td></tr><tr><td><p>STOR</p></td><td><p>Tell server to accept a file for storage.</p></td></tr><tr><td><p>STOU</p></td><td><p>Tell server to create unique name for new file.</p></td></tr><tr><td><p>STRU</p></td><td><p>Specify the file structure.</p></td></tr><tr><td><p>SYST</p></td><td><p>Tell server to declare its operating system.</p></td></tr><tr><td><p>TYPE</p></td><td><p>Specify the data representation type.</p></td></tr><tr><td><p>USER</p></td><td><p>Specify the username.</p></td></tr></table><p><p>Exactly which FTP commands are available depends on the server; someservers implement a subset, or possibly a superset, of the commandsdefined in the RFC. Net::FTP, which we'll discuss inthis chapter, provides methods that implement all the commands exceptthe following:</p><blockquote class="simplelist"><p>ALLO</p><p>HELP</p><p>MODE</p><p>REIN</p><p>SITE</p><p>SMNT</p><p>STAT</p><p>STRU</p><p>SYST</p></blockquote></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch17_03.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="ch18_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">17.3. The News::Newsrc Module</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">18.2. Net::FTP</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 &copy; 2002</a> O'Reilly &amp; 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 + -