FTP Imp RC

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 48

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? FTPs connections FTP in action FTP commands/responses

Trivial File Transfer Protocol (RFC 1350)

TFTP and TFTPs message formats

FTP and TFTP compared


FTP 2

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

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

The FTP Model


PI: Protocol Interpreter DTP: Data Transfer Protocol User Interface User

Server PI

Control

User PI

File System

Server DTP

Data

User DTP

File System

FTP

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.
FTP 6

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).

FTP

FTPs Connections
client
User Interface

* Non-persistent Persistent command * Insulates users from raw data Server is listening on port 21 *Server uses FTP portcommands 20 * Routes raw and reply connection FTP commands for connection requests for data servers connections * connection Receives replies
server

User Protocol Interpreter

Control Connection

Server Protocol 21 Interpreter

User Data Data Transfer Connection Function

Server Data Transfer 20 Function

FTPs

Connections Establishment
client Connected to cse.unr.edu 220 cse FTP server ready. 530 Please login with USER and PASS 331 Password req for mgunes. Password: 230 User mgunes logged in. ftp> USER PASS mgunes mypass server

ftp> open cse.unr.edu

User Interface

User Protocol Interpreter

Control Connection

Server Protocol Interpreter

User Data Data Transfer Connection Function

Server Data Transfer Function

FTPs

Connections Data Transfer


client ls client.txt -rw-r--r-- mgunes client.txt 226 Data Connection PORT 200 Closing LIST Port 192,168,100,173,19,137 client.txt Command Sucessful 150 Data Connection will be open shortly server

User Interface

User Protocol Interpreter

Control Connection

Server Protocol Interpreter

Passive open on Port 5001 User Data Data Transfer Connection Function Server Data Transfer Function

Establish Data Connection

FTPs

Connections Connection Closing


client bye

User Interface

221 Service Closing QUIT server

User Protocol Interpreter

Control Connection

Server Protocol Interpreter

User Data Data Transfer Connection Function

Server Data Transfer Function

FTP Connections

FTP

12

FTP Client Commands (issued by user interface)


Command get filename mget filename* put filename mput filename* open server bye / close / exit ls / dir Description
Retrieve file from server Retrieve multiple files from server* Copy local file to server Copy multiple local files to server* Begin login to server Logoff server List files in current remote dir on server

Change local directory lcd Change remote directory cd Lists commands the server accepts rhelp / remotehelp * Sent to server as multiple command by User Protocol Interpreter

Access Control Commands


USER PASS CWD

specify user specify password change directory

CDUP
QUIT

change directory to parent


logout

FTP

14

Transfer Parameter Commands


PORT
PASV TYPE

publish local data port


server should listen
establish data representation

MODE
STRU

establish transfer mode


establish file structure

FTP

15

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.
FTP 16

Service Commands
RETR

retrieve file

STOR
STOU APPE ABOR PWD

send file
send file and save as unique send file and append abort prev. service command print working directory

LIST

transfer list of files over data link


FTP

17

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.

FTP

18

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 - cant do).

FTP

19

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. FTP

20

Example FTP Responses

120

Service will be ready shortly

200
230

Command OK
User login OK

331
421 530 552

User name OK; password is needed


Service not available User not logged in
Requested action aborted; exceeded storage allocation
FTP 21

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

FTP

22

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

Diskless Workstation Booting 1


The call for help
Help! I don't know who I am! My Ethernet address is: 4C:23:17:77:A6:03 RARP Diskless Workstation

TFTP

25

The answer from the all-knowing

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

RARP Server

Diskless Workstation RARP REPLY

TFTP

26

The request for instructions


I need the file named boot-128.113.45.211

Diskless Workstation

TFTP Request (Broadcast)

TFTP

27

The dialog
here is part 1
I got part 1 TFTP Server

here is part 2
Diskless Workstation

boot file

TFTP File Transfer

TFTP

28

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

TFTP Message Formats

OPCODE

FILENAME

MODE DATA

OPCODE BLOCK# OPCODE BLOCK# OPCODE BLOCK#


2 bytes 2 bytes

ERROR MESSAGE

0
TFTP 30

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

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

Read Request
01 filename
null terminated ascii string containing name of file 2 byte opcode network byte order

mode

null terminated ascii string containing transfer mode

variable length fields!


TFTP 33

Write Request
02 filename
null terminated ascii string containing name of file 2 byte opcode network byte order

mode

null terminated ascii string containing transfer mode

variable length fields!


TFTP 34

TFTP Data Packet


03 block # data 0 to 512 bytes

2 byte block number network byte order


2 byte opcode network byte order all data packets have 512 bytes except the last one.

TFTP

35

TFTP Acknowledgment

04

block #

2 byte opcode network byte order

2 byte block number network byte order

TFTP

36

TFTP Error Packet


05 errcode errstring 0

2 byte opcode network byte order

null terminated ascii error string

2 byte error code network byte order

TFTP

37

TFTP Error Codes (16 bit int)


0 - not defined 1 - File not found 2 - Access violation 3 - Disk full 4 - Illegal TFTP operation 5 - Unknown port 6 - File already exists 7 - No such user

TFTP

38

TFTP Connection Establishment

TFTP

39

TFTP Session

TFTP

40

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

"sorcerers apprentice syndrome".

TFTP

41

Sorcerers Apprentice Syndrome


send 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

The Fix
Sender should not resend a data packet in

response to a duplicate ACK.

If sender receives ACK[n]

dont send DATA[n+1] if the ACK was a duplicate.

TFTP

43

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

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

When is it over?
There is no

length of file field sent! except the last one contain

All data messages

512 bytes of data.

message length is 2 + 2 + 512 = 516

The last data message might contain 0 bytes

of data!

TFTP

46

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

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 files
TFTP 48

You might also like