Anda di halaman 1dari 43

Chapter21

FileTransfer:
FTP
and
TFTP
TCP/IP Protocol Suite
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

OBJECTIVES:
To discuss FTP and two connections used in this protocol:
control connection and data connection.
To discuss six classes of commands sent by the client to establish
communication with the server.
To explain three types of file transfer transferred by FTP.
To show some user-friendly commands used by some FTP
interfaces.
To discuss anonymous FTP and its application.
To discuss how file transfer can be done using a secure channel.
To discuss TFTP as a simple file transfer protocol without the
complexities and sophistication of FTP.
TCP/IP Protocol Suite

OBJECTIVES (continued):
To discuss five types of TFTP messages and their applications.
To discuss the sorcerers apprentice bug related to TFTPs flowand error-control mechanisms.
To show how TFTP can be used in conjunction with DHCP to
initialize devices by downloading configuration files.

TCP/IP Protocol Suite

Chapter 21.1
Outline
21.2
21.2

TCP/IP Protocol Suite

FTP
TFTP

211FTP
File Transfer Protocol (FTP) is the
standard mechanism provided by TCP/IP
for copying a file from one host to
another. Although transferring files from
one system to another seems simple and
straightforward, some problems must be
dealt with first. For example, two systems
may use different file name conventions.
Two systems may have different ways to
represent text and data. Two systems may
have different directory structures. All of
these problems have been solved by FTP
5
TCP/IP Protocol Suite
in a very simple and elegant approach.

TopicsDiscussedintheSection
Connections
Communication
Command Processing
File Transfer
Anonymous FTP
Security for FTP
The sftp Program

TCP/IP Protocol Suite

Note

FTP uses the services of TCP.


It needs two TCP connections. The wellknown port 21 is used for the control
connection and the well-known
port 20 for the data connection.

TCP/IP Protocol Suite

Figure 21.1

TCP/IP Protocol Suite

FTP

Figure 21.2

TCP/IP Protocol Suite

Opening the control connection

Figure 21.3

TCP/IP Protocol Suite

Creating the data connection

10

Figure 21.4

TCP/IP Protocol Suite

Using the control connection

11

Figure 21.5

TCP/IP Protocol Suite

Using the data connection

12

Figure 21.6

TCP/IP Protocol Suite

Command processing

13

TCP/IP Protocol Suite

14

TCP/IP Protocol Suite

15

TCP/IP Protocol Suite

16

TCP/IP Protocol Suite

17

TCP/IP Protocol Suite

18

TCP/IP Protocol Suite

19

TCP/IP Protocol Suite

20

TCP/IP Protocol Suite

21

Figure 21.7

TCP/IP Protocol Suite

File transfer

22

Example 21.1
Figure 21.8 shows an example of using FTP for
retrieving a list of items in a directory.

TCP/IP Protocol Suite

23

Figure 21.8

Example 21.1

220 (Service ready)


2

USER forouzan
331 (User name OK. Password?)

PORT 8888
150 (Data connection opens shortly)

PASS xxxxxx
230 (User login OK)

LIST /usr/user/forouzan/reports
125 (Data connection OK)

DATA
TRANSFER

226 (Closing data connection)


13

10

List of files or directories

11

12

QUIT
221 (Service closing)

TCP/IP Protocol Suite

List of files or directories

14

24

Example 21.2
The following shows an actual FTP session that
parallels Example 21.1. The colored lines show
the
responses
from
the
server
control
connection; the black lines show the commands
sent by the client. The lines in white with black
background show data transfer.

TCP/IP Protocol Suite

25

Example 21.3
Figure 21.9 shows an example of how an image
(binary) file is stored.

TCP/IP Protocol Suite

26

Figure 21.9

Example 21.3

220 (Service ready)


2

USER forouzan
331 (User name OK. Password?)

STRU R
200 (OK)

12

TYPE EBCDIC
200 (OK)

10

PORT 1267
150 (Data connection opens shortly)

PASS xxxxxx
230 (User login OK)

11

STOR/usr/user/forouzan/reports/file1
250 (OK)

13

DATA
TRANSFER

17

TCP/IP Protocol Suite

226 (Closing data connection)


QUIT
221 (Service closing)

16

14

Records of file ..........

15

Records of file ..........

18

27

Example 21.4
We show an example of anonymous FTP. We
assume that some public data are available at
internic.net.

TCP/IP Protocol Suite

28

212TFTP
There are occasions when we need to
simply copy a file without the need for all
of the features of the FTP protocol. For
example, when a diskless workstation or
a router is booted, we need to download
the bootstrap and configuration files.
Here we do not need all of the
sophistication provided in FTP. We just
need a protocol that quickly copies the
files.
TCP/IP Protocol Suite

29

TopicsDiscussedintheSection
Messages
Connection
Data Transfer
UDP Ports
TFTP Example
TFTP Options
Security
Applications

TCP/IP Protocol Suite

30

Note

TFTP uses the services of UDP on the


well-known port 69.

TCP/IP Protocol Suite

31

Figure 21.10

TCP/IP Protocol Suite

Message categories

32

Figure 21.11

TCP/IP Protocol Suite

RRQ format

33

Figure 21.12

TCP/IP Protocol Suite

WRQ format

34

Figure 21.13

TCP/IP Protocol Suite

Data Format

35

Figure 21.14

TCP/IP Protocol Suite

ACK format

36

Figure 21.15

TCP/IP Protocol Suite

ERROR format

37

TCP/IP Protocol Suite

38

Figure 21.16

TCP/IP Protocol Suite

Connection establishment

39

Figure 21.17

TCP/IP Protocol Suite

Servers apprentice bug

40

Figure 21.18

TCP/IP Protocol Suite

UDP port numbers used by TFTP

41

Figure 21.19

TCP/IP Protocol Suite

TFTP example

42

Figure 21.20

Use of TFTP with DHCP

1
2

4
5

TCP/IP Protocol Suite

43

Anda mungkin juga menyukai