File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and - - PowerPoint PPT Presentation

file transfer protocol ftp
SMART_READER_LITE
LIVE PREVIEW

File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and - - PowerPoint PPT Presentation

File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007 , TAIWAN 1 Contents CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP LAB


slide-1
SLIDE 1

1

File Transfer Protocol (FTP)

Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN

slide-2
SLIDE 2

2

Contents

CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP – LAB 3

slide-3
SLIDE 3

3

File Transfer Protocol (1)

Transferring files from one computer to another Using two connections between hosts

One for data transfer One for control information

slide-4
SLIDE 4

4

File Transfer Protocol (2)

Three components for clients: user interface, client control process, and client data transfer process Two components for servers: server control process and server data transfer process

slide-5
SLIDE 5

5

File Transfer Protocol (3)

FTP uses the services of TCP FTP uses the services of TCP The well The well-

  • known port 21 is used for the

known port 21 is used for the control connection control connection The well The well-

  • known port 20 for the data

known port 20 for the data connection connection

slide-6
SLIDE 6

6

The control connection remains connected during the entire interactive FTP session; the data connection is opened and then closed for each file transferred.

slide-7
SLIDE 7

7

Contents

CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP – LAB 3

slide-8
SLIDE 8

8

Control Connection

Created in the same ways as other applications

Server issues a passive open on port 21 and waits Clients uses an ephemeral port and issues an active open

Remains open during the entire process Needs minimize delay for service

slide-9
SLIDE 9

9

slide-10
SLIDE 10

10

Data Connection

Uses the port 20 usually at the server side Creation of a data connection includes

Client issues a passive open using an ephemeral port Client sends this port number to the server using PORT command Server receives the port number and issues an active open using the well-known port

slide-11
SLIDE 11

11

slide-12
SLIDE 12

12

Contents

CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP – LAB 3

slide-13
SLIDE 13

13

Communication

FTP client and server run on different computers using different OS, character sets, and file formats. FTP must take this heterogeneity compatible Communication over

Control connection Data connection

slide-14
SLIDE 14

14

Communication over Control Connection

Uses the NVT ASCII character set Achieves the communication by commands and responses Each command or response is a short line terminated with a two-character (CR+LF) end-of-line token

slide-15
SLIDE 15

15

NVT

slide-16
SLIDE 16

16

Using the Control Connection

slide-17
SLIDE 17

17

Communication over Data Connection

Transfer files through the data connection The client must define

File type Data structure Transmission mode

Before sending the file through the data connection, we prepare for transmission through control connection

slide-18
SLIDE 18

18

File Type

ASCII file

default format for transferring text file

EBCDIC file Image file

default format for transferring binary files Mostly used to transfer binary files such as compiled programs

Nonprint v.s. TELNET attribute

slide-19
SLIDE 19

19

Data Structure

File structure (default)

Continuous stream of bytes

Record structure

Divided into records (or structs in C) Used only with text files

Page structure

Divided into pages each having a page number and header Can be stored or accessed randomly or sequentially

slide-20
SLIDE 20

20

Transmission Mode

Stream mode

Default mode Data are delivered from FTP to TCP as a continuous stream of bytes

Block mode Compressed Mode

slide-21
SLIDE 21

21

Using the data connection

slide-22
SLIDE 22

22

Contents

CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP – LAB 3

slide-23
SLIDE 23

23

Command Processing

FTP uses the control connection to communication. Commands are sent from the client to the server and the responses are sent back from the server to the client.

slide-24
SLIDE 24

24

Command Processing

slide-25
SLIDE 25

25

Commands

In the form of ASCII uppercase May be followed by an argument Six groups:

Access commands File management commands Data format commands Port defining commands File transferring commands Miscellaneous commands

slide-26
SLIDE 26

26

Access Commands

include

USER user-id PASS user-passwd ACCT account to be changed REIN QUIT ABOR

slide-27
SLIDE 27

27

File Management Commands

includes

CWD dir CDUP DELE file LIST dir NLIST dir MKD dir PWD RMD dir

slide-28
SLIDE 28

28

Data Formatting Commands

includes

TYPE A(ASCII), E(EBCDIC), I (Image), N (Nonprint), or T(TELNET) STRU F (File), R (Record), or P (page) MODE S (Stream), B (Block), or C (Compressed)

slide-29
SLIDE 29

29

Port Defining Commands

Define the port number for the data connection on the client site

Selects an port number and sends it to the server using a passive open Asks the server to choose a port number and send the port number in the response and then the client creates an active open using that port

Two commands

PORT (6-digits id) PASV

slide-30
SLIDE 30

30

File Transfer Commands

include

RETR file(s) STOR file(s) APPE file(s) STOU file(s) ALLO file(s) REST file(s) STAT file(s)

slide-31
SLIDE 31

31

Miscellaneous Commands

include

HELP NOOP SITE SYST

slide-32
SLIDE 32

32

Responses

Each FTP command generates at least one response Each response has two parts:

3-digit number: defines the code Text: defined needed parameters or extra explanations

slide-33
SLIDE 33

33

Contents

CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP – LAB 3

slide-34
SLIDE 34

34

File Transfer

One of the three things

Retrieving a file (RETR) Storing a file (STOR) Listing directory or file names (LIST) Note that, FTP treats a list of directory or file name as a file and sends it over the data connection.

slide-35
SLIDE 35

35

File transfer

slide-36
SLIDE 36

36

Example of Retrieving a List

slide-37
SLIDE 37

37

Example of storing an image (binary) file

slide-38
SLIDE 38

38

Contents

CONNECTIONS COMMUNICATION COMMAND PROCESSING FILE TRANSFER SIMPLE FTP – LAB 3

slide-39
SLIDE 39

39

LAB 3 – Simple FTP Client

Implement a simple FTP client Start your ftp service on the client side by typing sftp To connect to a server, use open command

  • pen hostname (or IP)

Exit the service by giving the bye command

slide-40
SLIDE 40

40

Commands to be Implemented

Two categories for the other commands

Commands on the remote machine ls, cd, get, mget, put, mput Commands on the local machine lls, lcd

slide-41
SLIDE 41

41

General Commands

USER id PASS password PORT h1,h2,h3,h4,p1,p2

PORT 140,124,182,140,4,200 IP:140.124.182.140 Port:4*256+200=1224

TYPE mode

AASCII IBinary

slide-42
SLIDE 42

42

General Commands

LIST RETR path

download

STOR path

upload

QUIT PASV

Return h1,h2,h3,h4,p1,p4

slide-43
SLIDE 43

43

Login & Logout Scenario

slide-44
SLIDE 44

44

Some Details

slide-45
SLIDE 45

45

Basic Commands (1/5)

USER <SP> <username> <CRLF>

The username is required by the server for access to its file system.

PASS <SP> <password> <CRLF>

The argument field is a TELNET string identifying the user's password.

QUIT <CRLF>

This command terminates a USER and if file transfer is not in progress, the server closes the TELNET connection.

slide-46
SLIDE 46

46

Basic Commands (2/5)

PORT <SP> <Host-port> <CRLF>

The argument is a HOST-PORT specification for the data port to be used in data connection. A port command would be: PORT h1,h2,h3,h4,p1,p2 where, h1 is the high order 8 bits of the internet host address.

slide-47
SLIDE 47

47

Basic Commands (3/5)

PASV <CRLF>

This command requests the server to "listen" on a data port (which may not be its default data port) and to wait for a connection rather than initiate one upon receipt of a transfer command. Server replies a code : 227 Entering Passive Mode. h1,h2,h3,h4,p1,p2

slide-48
SLIDE 48

48

Basic Commands (4/5)

TYPE <SP> <type code> <CRLF>

The argument specifies the representation type, for example:

A - ASCII I - Image

RETR <SP> <pathname> <CRLF>

This command causes the server to transfer a copy of the file, specified in the pathname, to the server or user at the other end of the data connection.

slide-49
SLIDE 49

49

Basic Commands (5/5)

STOR <SP> <pathname> <CRLF> This command causes the server to accept the data transferred via the data connection and to store the data as a file at the server site. CWD <SP> <pathname> <CRLF> This command allows the user to work with a different directory or dataset for file storage or retrieval without altering his login or accounting information. LIST [<SP> <pathname>] <CRLF> This command causes a list to be sent from the server to the client. PWD <CRLF> Return the current location of direction

slide-50
SLIDE 50

50

The open command

Client Server USER username Reply a code PASS password Reply a code

slide-51
SLIDE 51

51

The bye command

QUIT Reply a code Client Server Reply a code

slide-52
SLIDE 52

52

The ls command

Client Server PASV Reply a code Connect to the data connection socket Transmit the information of direction by data connection socket LIST <pathname> Rely a code Rely a code Close the data connection socket

slide-53
SLIDE 53

53

The cd command

Client Server CWD pathname Reply a code PWD Reply a code

slide-54
SLIDE 54

54

The got command

Client Server PASV Reply a code Connect to the data connection socket Reply a code RETR filename Reply a code Transmit the file though data connection socket Close the data connection socket

slide-55
SLIDE 55

55

The put command

Client Server PASV Reply a code Connect to the data connection socket Reply a code STOR filename Reply a code Transmit the file though data connection socket Close the data connection socket