Top Banner
Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes
48

Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Lecture 10

FTP & TFTP

CPE 401 / 601Computer Network Systems

slides are modified from Dave Hollinger and Michael mgunes

Page 2: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Overview File Transfer Protocol (RFC 959)

• Why FTP?

• FTP’s connections

• FTP in action

• FTP commands/responses

Trivial File Transfer Protocol (RFC 1350)

• TFTP and TFTP’s message formats

• FTP and TFTP compared FTP 2

Page 3: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Why do we need a FTP Service? Purpose: To Transfer files between two

computers

Goals of FTP Service

• Promote sharing of files (programs and/or data)

• Encourage indirect/implicit use of remote computers

• Shield users from variations in file storage among hosts

• Transfer data reliably and efficiently

FTP 3

Page 4: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Problems of File Transfer

At first, file transfer may seem simple Heterogeneous systems use different:

Operating Systems

Character Sets

Naming Conventions

Directory Structures

File Structures and Formats

FTP need to address and resolve these problems

FTP 4

Page 5: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 5

The FTP Model

Server PIServer PI

FileFileSystemSystem

User InterfaceUser Interface

User PIUser PI

UserUser

User DTPUser DTPServer DTPServer DTPFileFileSystemSystem

DataData

ControlControl

PI: Protocol InterpreterPI: Protocol InterpreterDTP: Data Transfer ProtocolDTP: Data Transfer Protocol

PI: Protocol InterpreterPI: Protocol InterpreterDTP: Data Transfer ProtocolDTP: Data Transfer Protocol

Page 6: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 6

Control and Data Connections• Control functions (commands) and reply

codes are transferred over the control connection.

• All data transfer takes place over the data connection.

• The control connection must be “up” while data transfer takes place.

Page 7: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 7

Control Connection

• The control connection is the “well known” service.

• The control connection uses the TELNET protocol.

• Commands and replies are all line oriented text (default is ASCII).

Page 8: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP’s Connections

UserInterface

User Data Transfer Function

UserProtocolInterpreter

ServerProtocolInterpreter

Server Data Transfer Function

client

server

ControlConnection

DataConnection

* Insulates users from “raw” FTP commandsServer is listening on port 21for connection requests

* Routes “raw” FTP commands * Receives server’s replies

* Persistent command and reply connection

Non-persistent data connection

21

20

*Server uses port 20for data connections

Page 9: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP’s Connections – Establishment

UserInterface

User Data Transfer Function

UserProtocolInterpreter

ServerProtocolInterpreter

Server Data Transfer Function

client

server

ControlConnection

DataConnection

ftp> open cse.unr.eduConnected to cse.unr.edu220 cse FTP server ready.530 Please login with USER and PASS

USER mgunes

331 Password req for mgunes.Password:

PASS mypass

230 User mgunes logged in.ftp>

Page 10: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP’s Connections Data Transfer

User Data Transfer Function

Server Data Transfer Function

UserInterface

UserProtocolInterpreter

ServerProtocolInterpreter

client

server

ControlConnection

DataConnection

ls client.txt

Passive open onPort 5001

PORT 192,168,100,173,19,137200 Port Command SucessfulLIST client.txt150 Data Connection will be open shortly226 Closing Data Connection

-rw-r--r-- mgunes client.txt

Establish Data Connection

UserProtocolInterpreter

ServerProtocolInterpreter

Page 11: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP’s Connections – Connection Closing

UserInterface

UserProtocolInterpreter

ServerProtocolInterpreter

client

server

ControlConnection

DataConnection

User Data Transfer Function

Server Data Transfer Function

bye

QUIT221 Service Closing

Page 12: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP Connections

FTP 12

Page 13: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP Client Commands (issued by user interface)

Command Description

get filename Retrieve file from server

mget filename* Retrieve multiple files from server*

put filename Copy local file to server

mput filename* Copy multiple local files to server*

open server Begin login to server

bye / close / exit Logoff server

ls / dir List files in current remote dir on server

lcd Change local directory

cd Change remote directory

rhelp / remotehelp Lists commands the server accepts

* Sent to server as multiple command by User Protocol Interpreter

Page 14: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 14

Access Control Commands

USER specify user

PASS specify password

CWD change directory

CDUP change directory to parent

QUIT logout

Page 15: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 15

Transfer Parameter Commands

PORT publish local data port

PASV server should listen

TYPE establish data representation

MODE establish transfer mode

STRU establish file structure

Page 16: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 16

Data Transfer Modes

• STREAM: • file is transmitted as a stream of bytes.

• BLOCK: • file is transmitted as a series of blocks

preceded by headers containing count and descriptor code (EOF, EOR, restart marker).

• COMPRESSED: • uses a simple compression scheme -

compressed blocks are transmitted.

Page 17: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 17

Service Commands

RETR retrieve file

STOR send file

STOU send file and save as unique

APPE send file and append

ABOR abort prev. service command

PWD print working directory

LIST transfer list of files over data link

Page 18: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 18

FTP Replies

• All replies are sent over control connection.

• Replies are a single line containing 3 digit status code (sent as 3 numeric chars). text message.

• The FTP spec. includes support for multiline text replies.

Page 19: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 19

FTP Reply Status Code

First digit of status code indicates type of reply:

‘1’: Positive Preliminary Reply (got it, but wait).

‘2’: Positive Completion Reply (success).

‘3’: Positive Intermediate Reply (waiting for more information).

‘4’: Transient Negative Completion (error - try again).

‘5’: Permanent Negative Reply (error - can’t do).

Page 20: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 20

FTP Reply Status Code

• 2nd digit indicates function groupings.

‘0’: Syntax (problem with command syntax).

‘1’: Information (reply to help or status cmds).

‘2’: Connections (problem with a connection).

‘3’: Authentication (problem with login).

‘4’: Unspecified.

‘5’: File system (related to file system).

• 3rd digit indicates specific problem within function group.

Page 21: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Example FTP Responses

• 120 Service will be ready shortly

• 200 Command OK

• 230 User login OK

• 331 User name OK; password is needed

• 421 Service not available

• 530 User not logged in

• 552 Requested action aborted; exceeded storage allocation

FTP 21

Page 22: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP 22

RFC 959

• The RFC includes lots more information and many details including: parameters for commands

lists of reply status codes

protocol state diagrams

support for a variety of file structures

sample sessions

Page 23: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.
Page 24: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Trivial FTP (TFTP)• Used only to read and write files

from/to a remote server– Cannot list directories

• Useful for bootstrapping diskless systems– Workstations– X terminals

• Simple and small:– 5 message formats– Runs on UDP– Designed to fit in ROM– Uses a “stop and wait” protocol– NO BUILT IN SECURITY FEATURES (login) TFTP 24

Page 25: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Diskless Workstation Booting 1The call for help

DisklessWorkstation

Help! I don't know who I am!My Ethernet address is:4C:23:17:77:A6:03

RARP

TFTP 25

Page 26: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP 26

The answer from the all-knowing

DisklessWorkstation

I know all! You are to be know as: 128.113.45.211

RARP REPLY

RARPServer

Page 27: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP 27

DisklessWorkstation

I need the file named boot-128.113.45.211

TFTP Request (Broadcast)

The request for instructions

Page 28: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP 28

The dialog

DisklessWorkstation

TFTP File Transfer

TFTPServer

here is part 1

I got part 1

here is part 2

boot file

Page 29: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Protocol

5 message types: Read request Write request Data ACK (acknowledgment) Error

Each is an independent UDP Datagram Each has a 2 byte opcode (1st 2 bytes) The structure of the rest of the

datagram depends on the opcode.

TFTP 29

Page 30: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Message Formats

FILENAMEOPCODE 0 0MODE

BLOCK# DATA

BLOCK#

OPCODE

OPCODE

OPCODE BLOCK# ERROR MESSAGE 0

2 bytes 2 bytes TFTP 30

Page 31: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP transfer modes

octet : for transferring binary files. no translation done.

netascii : for transferring text files. all lines end with \r\n (CR,LF). provides standard format for transferring text

files. both ends responsible for converting to/from

netascii format.

TFTP 31

Page 32: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

NetAscii Transfer Mode

Unix - end of line marker is just '\n'

receiving a file you need to remove '\r' before storing data.

sending a file you need to replace every '\n' with "\r\n"

before sending

TFTP 32

Page 33: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP 33

01 filename 0 mode 0

2 byte opcode2 byte opcodenetwork byte ordernetwork byte order

null terminated ascii stringnull terminated ascii stringcontaining name of filecontaining name of file

null terminated ascii stringnull terminated ascii stringcontaining transfer modecontaining transfer mode

variable length fields!variable length fields!

Read Request

Page 34: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Write Request

02 filename 0 mode 0

2 byte opcode2 byte opcodenetwork byte ordernetwork byte order

null terminated ascii stringnull terminated ascii stringcontaining name of filecontaining name of file

null terminated ascii stringnull terminated ascii stringcontaining transfer modecontaining transfer mode

variable length fields!variable length fields!TFTP 34

Page 35: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Data Packet

03 block # data 0 to 512 bytes

2 byte opcode2 byte opcodenetwork byte ordernetwork byte order

2 byte block number2 byte block numbernetwork byte ordernetwork byte order

all data packets have 512 bytesall data packets have 512 bytesexcept the last one.except the last one.

TFTP 35

Page 36: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Acknowledgment

04 block #

2 byte opcode2 byte opcodenetwork byte ordernetwork byte order

2 byte block number2 byte block numbernetwork byte ordernetwork byte order

TFTP 36

Page 37: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Error Packet

05 errcode errstring

2 byte opcode2 byte opcodenetwork byte ordernetwork byte order

2 byte error code2 byte error codenetwork byte ordernetwork byte order

null terminated ascii error stringnull terminated ascii error string

0

TFTP 37

Page 38: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Error Codes (16 bit int)

0 - not defined1 - File not found2 - Access violation3 - Disk full4 - Illegal TFTP operation5 - Unknown port6 - File already exists7 - No such user

TFTP 38

Page 39: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Connection Establishment

TFTP 39

Page 40: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Session

TFTP 40

Page 41: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Lost Data Packets - Original Protocol Specification

Sender uses a timeout with retransmission. sender could be client or server.

Duplicate data packets must be recognized and ACK retransmitted.

This original protocol suffers from the "sorcerer’s apprentice syndrome".

TFTP 41

Page 42: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Sorcerer’s Apprentice Syndromesend DATA[n]

(time out)retransmit DATA[n]

receive ACK[n]send DATA[n+1]

receive ACK[n] (dup)send DATA[n+1](dup)

...

receive DATA[n]send ACK[n]

receive DATA[n] (dup)send ACK[n] (dup)

receive DATA[n+1] send ACK[n+1]

receive DATA[n+1] (dup)send ACK[n+1] (dup)

TFTP 42

Page 43: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

The Fix

Sender should not resend a data packet in response to a duplicate ACK.

If sender receives ACK[n] don’t send DATA[n+1] if the ACK was a

duplicate.

TFTP 43

Page 44: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Concurrency

TFTP servers use a "well known address" (UDP port number).

How would you implement a concurrent server? forking (alone) may lead to problems! Can provide concurrency without forking, but it

requires lots of bookkeeping.

TFTP 44

Page 45: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

TFTP Concurrency

According to the protocol, the server may create a new udp port and send the initial response from this new port.

The client should recognize this, and send all subsequent messages to the new port.

TFTP 45

Page 46: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

When is it over?

There is no length of file field sent!

All data messages except the last one contain 512 bytes of data. message length is 2 + 2 + 512 = 516

The last data message might contain 0 bytes of data!

TFTP 46

Page 47: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

Issues

What if more than 65535 chunks are sent? 65536 blocks x 512 bytes/block = 33,554,432

bytes.

The RFC does not address this issue! Remember that the network can duplicate

packets!

TFTP 47

Page 48: Lecture 10 FTP & TFTP CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Michael mgunes.

FTP vs. TFTP FTP provides (minimal) security through login

procedure

TFTP has NO login procedure

FTP Provides a reliable service through its use of TCP

TFTP must handle its own retransmissions since it uses UDP

FTP uses two connections

TFTP uses one connection (stop and wait)

FTP provides many commands

TFTP can only read and write filesTFTP 48