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

📄 lsg43.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:


<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->


























<LINK REL="ToC" HREF="index.htm">







<LINK REL="Index" HREF="htindex.htm">







<LINK REL="Next" HREF="lsg44.htm">



















<A NAME="I0"></A>







<H2>Linux System Administrator's Survival Guide lsg43.htm</H2>







<P ALIGN=LEFT>







































<HR ALIGN=CENTER>







<P>







<UL>







<UL>







<UL>







<LI>







<A HREF="#E68E227" >What Is FTP?</A>







<LI>







<A HREF="#E68E228" > Using FTP</A>







<UL>







<LI>







<A HREF="#E69E243" >Transferring Files</A>







<UL>







<LI>







<A HREF="#E70E10" >Different File Formats</A></UL>







<LI>







<A HREF="#E69E244" >Quitting FTP</A>







<LI>







<A HREF="#E69E245" >How FTP Uses TCP</A></UL>







<LI>







<A HREF="#E68E229" >Configuring FTP</A>







<UL>







<LI>







<A HREF="#E69E246" >Setting Up ftpd</A>







<LI>







<A HREF="#E69E247" >FTP Logins</A>







<LI>







<A HREF="#E69E248" >Setting Up the Directories</A>







<LI>







<A HREF="#E69E249" >Setting Permissions</A>







<LI>







<A HREF="#E69E250" >Testing the System</A></UL>







<LI>







<A HREF="#E68E230" > Securing FTP</A>







<LI>







<A HREF="#E68E231" >Summary</A></UL></UL></UL>







<HR ALIGN=CENTER>







<A NAME="E66E49"></A>







<H1 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Chapter 43</B></FONT></CENTER></H1>







<BR>







<A NAME="E67E52"></A>







<H2 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Setting up an FTP and Anonymous FTP Site</B></FONT></CENTER></H2>







<BR>







<P>What is the most widely used TCP/IP and Internet service? If you answered FTP, you're right. (If you didn't choose FTP, this answer may come as a bit of a surprise, but FTP remains the most widely used service, although the World Wide Web is quickly catching up.) FTP's popularity is easy to understand. The FTP software is supplied with every version of UNIX and Linux; it's easy to install, configure, and use; and it gives users access to a wealth of information with very little effort.







<BR>







<P>Earlier chapters of this book have mentioned FTP, and most user-oriented books deal with using FTP in some detail. If all you want to use FTP for is connecting to another machine and transferring files, then you don't have to do much more than enable the FTP service on your system. Much more interesting to many is turning your Linux machine into an FTP site, where others can call in and obtain files you make available. That's the primary focus of this chapter: setting up an FTP site on your Linux machine. The chapter begins, though, with a quick look at using FTP and the way FTP runs on TCP. This information should help you understand how FTP works and what it does with TCP/IP.







<BR>







<BR>







<A NAME="E68E227"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>What Is FTP?</B></FONT></CENTER></H3>







<BR>







<P>The File Transfer Protocol (FTP) is one protocol in the TCP/IP family used to transfer files between machines running TCP/IP (FTP-like programs are also available for some other protocols). The File Transfer Protocol enables you to transfer files back and forth and manage directories. FTP is not designed to give you access to another machine to execute programs, but it is the best utility for file manipulation. To use FTP, both ends of a connection must be running a program that provides FTP services. The end that starts the connection (the client) calls the other end (the server) and establishes the FTP protocol through a set of handshaking instructions.







<BR>







<P>Usually, when you connect to a remote system via FTP, you must log in. In order to log in, you must be a valid user with a username and password for that remote machine. Because it is impossible to provide logins for everyone who wants to access a machine that allows anyone to gain access, many systems use anonymous FTP instead. Anonymous FTP allows anyone to log in to the system with the login name of ftp, guest, or anonymous and either no password or a login name for their local system.







<BR>







<BR>







<A NAME="E68E228"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B> Using FTP</B></FONT></CENTER></H3>







<BR>







<P>Using FTP to connect to a remote site is easy. You have access to the remote machine either through the Internet (directly or through a service provider) or through a wide or local area network if the remote machine is directly reachable. To use FTP, you start the FTP client software and provide the name of the remote system to which you want to connect. For example, assuming you can get to the remote machine through a LAN or the Internet (which knows about the remote machine thanks to DNS), you issue the following command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">ftp chatton.com</FONT></PRE>







<P>This command instructs your FTP software to try to connect to the remote machine chatton.com and establish an FTP session.







<BR>







<P>When the connection is completed (and assuming that the remote system allows FTP logins), the remote prompts for a userID. If anonymous FTP is supported on the system, a message usually tells you exactly that. The login following is shown for the Linux FTP archive site sunsite.unc.edu:







<BR>







<PRE>







<FONT COLOR="#000080">ftp sunsite.unc.edu







331 Guest login ok, send your complete e-mail address as password.







Enter username (default: anonymous): anonymous







Enter password [tparker@tpci.com]:







|FTP| Open







230- WELCOME to UNC and SUN's anonymous ftp server







230- University of North Carolina







230- Office FOR Information Technology







230- SunSITE.unc.edu







230 Guest login ok, access restrictions apply.







FTP&gt;</FONT></PRE>







<P>After the login process is completed, you see the prompt FTP&gt; indicating that the remote system is ready to accept commands.







<BR>







<P>When you log on to some systems, you may see a short message that may contain instructions for downloading files, any restrictions that are placed on you as an anonymous FTP user, or information about the location of useful files. For example, you may see messages like the following (taken from the Linux FTP site):







<BR>







<PRE>







<FONT COLOR="#000080">To get a binary file, type: BINARY and then: GET &quot;File.Name&quot; newfilename







To get a text file, type: ASCII and then: GET &quot;File.Name&quot; newfilename







Names MUST match upper, lower case exactly. Use the &quot;quotes&quot; as shown.







To get a directory, type: DIR. To change directory, type: CD &quot;Dir.Name&quot;







To read a short text file, type: GET &quot;File.Name&quot; TT







For more, type HELP or see FAQ in gopher.







To quit, type EXIT or Control-Z.







230- If you email to info@sunsite.unc.edu you will be sent help information







230- about how to use the different services sunsite provides.







230- We use the Wuarchive experimental ftpd. if you &quot;get&quot; &lt;directory&gt;.tar.Z







230- or &lt;file&gt;.Z it will compress and/or tar it on the fly. Using &quot;.gz&quot; instead







230- of &quot;.Z&quot; will use the GNU zip (/pub/gnu/gzip*) instead, a superior







230- compression method.</FONT></PRE>







<P>Once you are on the remote system, you can use familiar Linux commands to display file contents and move around directories. To display the contents of a directory, for example, use the command ls (some systems support the DOS equivalent DIR). To change to a subdirectory, use the cd command. To return to the parent directory (the one above the current directory), use the command cd ... As you can see, these commands are the same ones you would use on your local machine, except that you are now navigating on the remote system. To change directories on your local machine, you can use the lcd command.







<BR>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE>FTP has no keyboard shortcuts (such as pressing the Tab key to fill in names that match). You have to type in the name of files or directories in their entirety (and do so correctly). If you misspell a file or directory name, you will get error messages and have to try again. If you are performing the FTP session through an X window, you can cut and paste lines from earlier in your session. Users of gpm can cut and paste from character-based screens.</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<BR>







<A NAME="E69E243"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Transferring Files</B></FONT></CENTER></H4>







<BR>







<P>Transferring files is the whole point of FTP, so you need to know how to retrieve a file from the remote system, as well as how to put a new file there. When you have moved through the remote system's directories and found a file you want to move back to your local system, use the get command. Place the filename after the command, for example:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">get &quot;soundcard_driver&quot;</FONT></PRE>







<P>This command transfers the file soundcard_driver from the remote machine to the current directory on your local machine. When you issue a get command, the remote system transfers data to your local machine and display a status message when it is completed. There is no indication of progress when a large file is being transferred, so be patient. Many versions of FTP support a command called hash that displays a pound sign after every 1024 bytes has been transferred. This command gives you a visual indication of the progress of the transfer.







<BR>







<PRE>







<FONT COLOR="#000080">FTP&gt; get &quot;file1.txt&quot;







200 PORT command successful.







150 BINARY data connection for FILE1.TXT (27534 bytes)







226 BINARY Transfer complete.







27534 bytes received in 2.35 seconds (12 Kbytes/s).</FONT></PRE>







<P>If you want to transfer a file the other way (from your machine to the remote, assuming you are allowed to write to the remote machine's filesystem), use the put command in the same way. The following command transfers the file comments from your current directory on the local machine (you can specify full pathnames) to the current directory on the remote machine (unless you change the path).







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">put &quot;comments&quot;</FONT></PRE>







<P>The commands get (download) and put (upload) are always relative to your home machine. You are telling your system to get a file from the remote and put it on your local machine, or to put a file from your local machine onto the remote machine. (This process is the exact opposite of Telnet, which has everything relative to the remote machine. It is important to remember which command moves in which direction, or you could overwrite files accidentally.)







<BR>







<P>The quotation marks around the filenames in the preceding examples are optional for most versions of FTP, but they do prevent shell expansion of characters, so they can be recommended. For most files, the quotation marks are not needed, but using them is a good habit to get into.







<BR>







<P>Some FTP versions provide a wildcard capability using the commands mget and mput. Both the FTP get and put commands usually transfer only one file at a time, which must be specified completely (no wildcards). The mget and mput commands enable you to use wildcards. For example, to transfer all the files with a .doc extension, you could issue the following command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">mget *.doc</FONT></PRE>







<P>You have to try the mget and mput commands to see if they work on your FTP version. (Some FTP get and put commands allow wildcards, too, so you can try wildcards in a command line to see if they work.)







<BR>







<BR>







<A NAME="E70E10"></A>







<H5 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Different File Formats</B></FONT></CENTER></H5>







<BR>







<P>FTP allows file transfers in several formats, which are usually system-dependent. The majority of systems (including Linux systems) have only two modes: ASCII and binary. Some mainframe installations add support for EBCDIC, while many sites have a local type that is designed for fast transfers between local network machines (the local type may use 32- or 64-bit words).







<BR>







<P>The difference between the binary and ASCII modes is simple. Text transfers use ASCII characters separated by carriage return and newline characters. Binary mode allows transfer of characters with no conversion or formatting. Binary mode is faster than text and also allows for the transfer of all ASCII values (necessary for non-text files). FTP cannot transfer file permissions, as these are not specified as part of the protocol.







<BR>







<P>Linux's FTP provides two modes of file transfer: ASCII and binary. Some systems automatically switch between the two when they recognize that a file is in binary format, but you shouldn't count on the switching unless you've tested it before and know it works. To be certain, it is a good idea to set the mode manually. By default, most FTP versions start up in ASCII mode, although a few start in binary.







<BR>







<P>To set FTP in binary transfer mode (for any executable file or file with special characters embedded for spreadsheets, word processors, graphics, and so on), type the following command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">binary</FONT></PRE>







<P>You can toggle back to ASCII mode with the command ascii. Because you will most likely be checking remote sites for new binaries or libraries of source code, it is a good idea to use binary mode for most transfers. If you transfer a binary file in ASCII mode, it will not be executable on your system.







<BR>







<P>ASCII mode includes only the valid ASCII characters and not the Ctrl-key sequences used within binaries. Transferring an ASCII file in binary mode does not affect the contents except in very rare instances. When transferring files between two Linux (or any UNIX) systems, using binary mode will handle all file types properly, but transfers between a Linux and non-UNIX machine can cause problems with some types of files. ASCII mode is only suitable for transferring straight text files.







<BR>







<BR>







<A NAME="E69E244"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Quitting FTP</B></FONT></CENTER></H4>







<BR>







<P>To quit FTP, type the command quit or exit. Both will close your session on the remote machine, and then terminate FTP on your local machine. Users have a number of commands available within most versions of FTP, the most frequently used of which are the following:







<BR>















<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -