tips on ftp implementation

14
Tips on FTP Tips on FTP Implementation Implementation

Upload: wood

Post on 11-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Tips on FTP Implementation. FTP Model. User Commands. User Interface. User. FTP Commands. Server PI. User PI. FTP Replies. Port L. File System. Server DTP. User DTP. File System. Data Connection. Port L-1. FTP Server. FTP Client. PI: Protocol Interpreter - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Tips on FTP Implementation

Tips on FTP Tips on FTP ImplementationImplementation

Page 2: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 2

FTP Model

UserInterfac

e

UserPI

UserDTP

ServerDTP

ServerPI

User

FileSystem

FileSystem

FTP Commands

FTP Replies

DataConnection

FTP ServerFTP Server FTP ClientFTP Client

PI: Protocol InterpreterDTP: Data Transfer Process

UserCommands

Port L

Port L-1

Page 3: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 3

Commands: Minimum Implementation

User Cmd arguments FTP Cmd arguments Meaning

open <hostname> <hostname> Connect to FTP server

[user] <username> USER <username> User name

<password> PASS <password> Password

system SYST Show the type of OS running on the remote machine

nlist [<pathname>] NLST <pathname> Name list (ls)

ls, dir [<pathname>] LIST <pathname> Directory list (ls –l)

pwd PWD Print working directory

cd <pathname> CWD <pathname> Change working directory

lcd <pathname> Change local working directory

[type] ascii[type] binary

TYPETYPE

AI

A – NVT-ASCII textI – binary data

get <pathname> RETR <pathname> Retrieve: download the file

put <pathname> STOR <pathname> Store: upload the file

PASVSet server into passive mode. Server will reply 227 response with its IP and port

PORT h1,h2,h3,h4,p1,p2Data port for FTP client (Set server into active mode)h1,h1,h3,h4: IPv4 address, p1,p2: port number

close QUIT Close FTP session

bye, quit QUIT Close FTP session and exit

passivePassive mode on or off (toggle switch)If passive mode on, send PASV for data transferOtherwise, send PORT (active mode, default)

type FTP data type ?

debug Debug mode on or off (toggle switch

lcd <pathname> Change local working directory

Page 4: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 4

FTP Replies

Code Description

1yz Positive preliminary reply The command is being acted upon; expect a final reply code before sending another command

2yz Positive completion reply The command was successfully executed; a new command may be sent

3yz Positive intermediate reply The command was accepted, but the final result is being delayed because other information needs to be supplied from the client

4yz Transient negative completion reply The command failed, but the condition is temporary; the user agent should try again

5yz Permanent negative completion reply The command failed and will always fail if given again; the command should not be attempted again

Page 5: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 5

FTP Response Codes 125 Data connection already

open; transfer starting. 150 File status okay; about to

open data connection. 200 Command okay. 212 Directory status. 213 File status. 220 Service ready for new

user. 221 Service closing control

connection. 225 Data connection open;

no transfer in progress. 226 Closing data connection. 227 Entering Passive Mode

(203,253,69,113,201,131) 230 User logged in, proceed. 250 Requested file action

okay, completed.

331 User name okay, need password.

350 Requested file action pending further information.

421 Service not available, closing control connection.

425 Can't open data connection.

426 Connection closed; transfer aborted.

450 Requested file action not taken.

File unavailable (e.g., file busy). 500 Syntax error, command

unrecognized. 502 Command not

implemented. 530 Not logged in. 550 Requested action not

taken. File unavailable (e.g., file not

found, no access).

Page 6: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 6

Open and Closing FTP Sessions

Establish Control Connection

USER <user name>

331 Need passwdPASS <password>

230 User logged in

220 Service ready

QUIT

221 Service closing

User PI Server PI

<user name>

<password>

closebye, quit

UserInterfa

ce

open <host>or from argv

Data Transfer Session

설계 : State transition diagram - Event: User command, Reply msg-Action: send FTP command …* reply msg 에 대한 state transition 도포함해야

설계 : State transition diagram - Event: User command, Reply msg-Action: send FTP command …* reply msg 에 대한 state transition 도포함해야

State transition table 을 만든다면 , if-then-else 를 쓰지 않고 , table-driven programming 할 수 있지 않을까 ?

State transition table 을 만든다면 , if-then-else 를 쓰지 않고 , table-driven programming 할 수 있지 않을까 ?

Page 7: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 7

Data Transfer: get, out, ls- active mode (passive mode off)

User logged in

PORT h1,h2,h3,h4,p1,p2

200 Command Successful

RETR/STOR/LIST <file>

150 Opening data connection

226 Transfer Complete

UserPI

ServerPI

UserInterface

get/put/ls <file>

UserDTP

ServerDTP

Establish data connection

How to know the listening socket address? - IP addr: control connection socket에서 /* getsockname(controlfd, …); */ - port: 0 - bind(listenfd, …); /* kernel 이 사용하지 않는 port 를 선택 */ - listen(listenfd, …); - getsockname(listenfd, …); - send PORT command - datafd = accept(listenfd, … );

Data TransferClose connection

Page 8: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 8

Data Transfer: get, put, ls- passive mode on

PASV

227 Entering Passive Mode (203,253,69,113,201,131)

RETR/STOR/LIST <file>

150 Opening data connection

226 Transfer Complete

UserPI

ServerPI

UserInterface

get/put/ls <file>

UserDTP

ServerDTP

IP addr, port of server DTP(server’s listening socket addr)

IP addr, port of server DTP(server’s listening socket addr)

Establish data connection

Data TransferClose connection

Page 9: Tips on FTP Implementation

FTP command and Response

Jin Pyo Hong, HUFS Page 9

Page 10: Tips on FTP Implementation

More Specific Diagram

Jin Pyo Hong, HUFS Page 10

Login sequence

Wait forS reply

Wait forP reply

Wait forI reply

F4, 5

, 3

Wait forS reply

Page 11: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 11

State Transition Diagram open, user

Wait forUser Cmd

Wait forI reply

Wait forS reply

3PASS

2NULL

2NULLopen

Open control Connection

userUSER

Page 12: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 12

State Transition Diagram

pwd, cd, ascii, binary, system, close

Wait forUser Cmd

WaitFor S reply

1, 3Error

pwd, cd, ascii, binary, system, closePWD, CWD, TYPE A, TYPE I, SYST,

QUIT

2Success

4, 5Failure

Page 13: Tips on FTP Implementation

Jin Pyo Hong, HUFS Page 13

State Transition Diagram ls, dir, nlist, get, put

Wait forUser Cmd

Wait forS reply - 1

Wait forS reply - 2

Wait forP reply

DataTransfer

ls, dir, nlistType A

2PASV/ PORT

get, putPASV / PORT

2Connect/Listen

(LIST/NLIST/RETR/STOR)

1Pre Reply

2Close Data Connection

2Close Data Connection

Page 14: Tips on FTP Implementation

Event State Table

14

States

Events

Wait for user cmd (U_CMD)

Wait for S reply

(S_REPLY)

Wait forS reply-1(S_REPLY

1)

Wait forS reply-2(S_REPLY

2)

wait for S reply-3(S_REPLY3)

Wait forP reply

(P_REPLY)

Data transfer(DATA)

Wait forI reply

(I_REPLY)

From User

Interface

open

Open control connection

USERI_REPLY

userUSER

I_REPLY

nlist, ls, dirTYPE A

S_REPLY1

get, putPASV/PORT

S_REPLY2

pwd,, cd, ascii,

binary,system

PWD, CWD, TYPE A, TYPE I

SYST S_REPLY

close, bye, quit

QUITClose control connection S_REPLY3

lcd, type, passive, debug

Local action U_CMD

From FTP

Server

1yzError

U_CMDPre. Reply

DATAError

U_CMD

2yzIgnore

U_CMDSuccess

U_CMD

PASV/PORT

S_REPLY2

Connect or listenLIST/

NLIST/RETR/STOR P_REPLY

success U_CMD

or Exit (bye, quit)

Close data connection if not closed U_CMD

Password does not required U_CMD

3yzError

U_CMDPASS

S_REPLY

4yz, 5yzfailure

U_CMD