ch48.htm
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTM 代码 · 共 1,482 行 · 第 1/3 页
HTM
1,482 行
<TD WIDTH="58" ALIGN="LEFT"><TT>cd</TT> </TD>
<TD ALIGN="LEFT">Changes directory on the server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>close</TT> </TD>
<TD ALIGN="LEFT">Terminates the connection </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>del</TT> </TD>
<TD ALIGN="LEFT">Deletes a file on the server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>dir</TT> </TD>
<TD ALIGN="LEFT">Displays the server directory </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>get</TT> </TD>
<TD ALIGN="LEFT">Fetches a file from the server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>hash</TT> </TD>
<TD ALIGN="LEFT">Displays a pound character for each block transmitted </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>help</TT> </TD>
<TD ALIGN="LEFT">Displays help </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>lcd</TT> </TD>
<TD ALIGN="LEFT">Changes directory on the client </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>mget</TT> </TD>
<TD ALIGN="LEFT">Fetches several files from the server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>mput</TT> </TD>
<TD ALIGN="LEFT">Sends several files to the server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>open</TT> </TD>
<TD ALIGN="LEFT">Connects to a server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>put</TT> </TD>
<TD ALIGN="LEFT">Sends a file to the server </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>pwd</TT> </TD>
<TD ALIGN="LEFT">Displays the current server directory </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>quote</TT> </TD>
<TD ALIGN="LEFT">Supplies an FTP command directly </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="58" ALIGN="LEFT"><TT>quit<BR>
</TT></TD>
<TD ALIGN="LEFT">Terminates the FTP session<BR>
</TD>
</TR>
</TABLE>
For most versions, FTP commands are case sensitive, and using uppercase will display
error messages. Some versions perform a translation for you, so it doesn't matter
which case you use. Since Linux uses lowercase as its primary character set for everything
else, you should probably use lowercase with all versions of FTP, too.
<CENTER>
<H4><A NAME="Heading5<FONT COLOR="#000077">How FTP Uses TCP</FONT></H4>
</CENTER>
<P>The File Transfer Protocol uses two TCP channels: TCP port 20 is used for data,
and port 21 is for commands. Both these channels must be enabled on your Linux system
for FTP to function. The use of two channels makes FTP different from most other
file transfer programs. By using two channels, TCP allows simultaneous transfer of
FTP commands and data. FTP works in the foreground and does not use spoolers or queues.</P>
<P>FTP uses a server daemon that runs continuously and a separate program that is
executed on the client. On Linux systems, the server daemon is called <TT>ftpd</TT>.
The client program is <TT>ftp</TT>.</P>
<P>During the establishment of a connection between a client and server, and whenever
a user issues a command to FTP, the two machines transfer a series of commands. These
commands are exclusive to FTP and are known as the internal protocol. FTP's internal
protocol commands are four-character ASCII sequences terminated by a new-line character,
some of which require parameters. One primary advantage of using ASCII characters
for commands is that users can observe the command flow and understand it easily.
This helps in a debugging process. Also, the ASCII commands can be used directly
by a knowledgeable user to communicate with the FTP server component without invoking
the client portion (in other words, communicating with <TT>ftpd</TT> without using
<TT>ftp</TT> on a local machine); this is seldom used except when debugging (or showing
off).</P>
<P>After logging into a remote machine using FTP, you are not actually on the remote
machine. You are still logically on the client, so all instructions for file transfers
and directory movement must be with respect to your local machine and not the remote
one. This is the process followed by FTP when a connection is established:
<DL>
<DD><B>1.</B> Login--Verify user ID and password<BR>
<BR>
<B>2. </B>Define directory--Identify the starting directory<BR>
<BR>
<B>3.</B> Define file transfer mode--Define the type of transfer<BR>
<BR>
<B>4. </B>Start data transfer--Allow user commands<BR>
<B><BR>
5. </B>Stop data transfer--Close the connection
</DL>
<P>These steps are performed in sequence for each connection.</P>
<P>A debugging option is available from the FTP command line by adding <TT>-d</TT>
to the command. This displays the command channel instructions. Instructions from
the client are shown with an arrow as the first character, while instructions from
the server have three digits in front of them. A <TT>PORT</TT> in the command line
indicates the address of the data channel on which the client is waiting for the
server's reply. If no <TT>PORT</TT> is specified, channel 20 (the default value)
is used. Unfortunately, the progress of data transfers cannot be followed in the
debugging mode. A sample session with the debug option enabled is shown here:<FONT
COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">$ ftp -d tpci_hpws4
Connected to tpci_hpws4.
220 tpci_hpws4 FTP server (Version 1.7.109.2
ÂTue Jul 28 23:32:34 GMT 1992) ready.
Name (tpci_hpws4:tparker):
--> USER tparker
331 Password required for tparker.
Password:
--> PASS qwerty5
230 User tparker logged in.
--> SYST
215 UNIX Type: L8
Remote system type is UNIX.
--> Type I
200 Type set to I.
Using binary mode to transfer files.
ftp> ls
--> PORT 47,80,10,28,4,175
200 PORT command successful.
--> TYPE A
200 Type set to A.
--> LIST
150 Opening ASCII mode data connection for /bin/ls.
total 4
-rw-r---- 1 tparker tpci 2803 Apr 29 10:46 file1
-rw-rw-r-- 1 tparker tpci 1286 Apr 14 10:46 file5_draft
-rwxr---- 2 tparker tpci 15635 Mar 14 23:23 test_comp_1
-rw-r---- 1 tparker tpci 52 Apr 22 12:19 xyzzy
Transfer complete.
--> TYPE I
200 Type set to I.
ftp> <Ctrl-d>
$
</FONT></PRE>
<P>You may have noticed in the preceding listing how the mode changed from binary
to ASCII to send the directory listing, and then back to binary (the system default
value).
<CENTER>
<H3><A NAME="Heading6<FONT COLOR="#000077">Configuring FTP</FONT></H3>
</CENTER>
<P>Whether you decide to provide an anonymous FTP site or a user-login FTP system,
you need to perform some basic configuration steps to get the FTP daemon active and
get the directory system and file permissions properly set to prevent users from
destroying or accessing files they shouldn't. The process can start with choosing
an FTP site name. You don't really need a site name, although it can be easier for
others to access your machine with one (especially anonymously). The FTP site name
is of the format<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ftp.domain_name.domain_type
</FONT></PRE>
<P>where domain_name is the domain name (or an alias) of the FTP server's domain,
and domain_type is the usual DNS extension. For example, you could have an FTP site
name of<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ftp.tpci.com
</FONT></PRE>
<P>showing that this is the anonymous FTP access for anyone accessing the <TT>tpci.com</TT>
domain. It is usually a bad idea to name your FTP site with a specific machine name,
such as<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ftp.merlin.tpci.com
</FONT></PRE>
<P>because this makes it difficult to move the FTP server to another machine in the
future. Instead, use an alias to point to the actual machine on which the FTP server
sits. This is not a problem if you are a single machine connected to the Internet
through a service provider, for example, but it is often necessary with a larger
network. The alias is easy to set up if you use DNS. Set the alias in the DNS databases
with a line like this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ftp IN CNAME merlin.tpci.com
</FONT></PRE>
<P>This line points anyone accessing the machine <TT>ftp.tpci.com</TT> to the real
machine <TT>merlin.tpci.com</TT>. If the machine <TT>merlin</TT> has to be taken
out of its FTP server role for any reason, a change in the machine name on this line
will point the <TT>ftp.tpci.com</TT> access to the new server. (A change in the alias
performed over DNS can take a while to become active because the change must be propagated
through all the DNS databases.)
<CENTER>
<H4><A NAME="Heading7<FONT COLOR="#000077">Setting Up ftpd</FONT></H4>
</CENTER>
<P>The FTP daemon, <TT>ftpd</TT>, must be started on the FTP server. The daemon is
usually handled by <TT>inetd</TT> instead of the <TT>rc</TT> startup files, so <TT>ftpd</TT>
is only active when someone needs it. This is the best approach for all but the most
heavily loaded FTP sites. When started using <TT>inetd</TT>, the <TT>inetd</TT> daemon
watches the TCP command port (channel 21) for an arriving data packet requesting
a connection, and then spawns <TT>ftpd</TT>.</P>
<P>Make sure the <TT>ftpd</TT> daemon can be started by <TT>inetd</TT> by checking
the <TT>inetd</TT> configuration file (usually <TT>/etc/inetd.config</TT> or <TT>/etc/inetd.conf</TT>)
for a line that looks like this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ftp stream tcp nowait root /usr/etc/ftpd ftpd -l
</FONT></PRE>
<P>If the line doesn't exist, add it to the file. With most Linux systems, the line
is already in the file, although it may be commented out. Remove the comment symbol
if this is the case. The FTP entry essentially specifies to <TT>inetd</TT> that FTP
is to use TCP, and that it should spawn <TT>ftpd</TT> every time a new connection
is made to the FTP port. In the preceding example, the <TT>ftpd</TT> daemon is started
with the <TT>-l</TT> option, which enables logging. You can ignore this option if
you want. You should replace the pathname <TT>/usr/etc/ftpd</TT> with the location
of your FTP daemon.</P>
<P>There are several <TT>ftpd</TT> daemon options that you can add to the <TT>/etc/inetd.config</TT>
line to control <TT>ftpd</TT>'s behavior. The following list contains the most commonly
used options:
<TABLE BORDER="0">
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="30" ALIGN="LEFT" VALIGN="TOP"><TT>-d</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Adds debugging information to the syslog. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="30" ALIGN="LEFT" VALIGN="TOP"><TT>-l</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Activates a logging of sessions (only failed and successful logins, not debug information).
If the -l option is specified twice, all commands are logged, too. If specified three
times, the size of all get and put file transfers are added as well. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="30" ALIGN="LEFT" VALIGN="TOP"><TT>-t</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sets the timeout period before ftpd terminates after a session is concluded (default
is 15 minutes). The value is specified in seconds after the -t option. </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="30" ALIGN="LEFT" VALIGN="TOP"><TT>-T</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sets the maximum timeout period (in seconds) that a client can request. The default
is two hours. This lets a client alter the normal default timeout for some reason.
</TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="30" ALIGN="LEFT" VALIGN="TOP"><TT>-u</TT> </TD>
<TD ALIGN="LEFT" VALIGN="TOP">Sets the umask value for files uploaded to the local system. The default umask is
022. Clients can request a different umask value. </TD>
</TR>
</TABLE>
<CENTER>
<H4><A NAME="Heading8<FONT COLOR="#000077">FTP Logins</FONT></H4>
</CENTER>
<P>If you are going to set up a user-based FTP service where each person accessing
your system has a valid login name and password, then you must create an account
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?