Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tips on FTP Implementation

Similar presentations


Presentation on theme: "Tips on FTP Implementation"— Presentation transcript:

1 Tips on FTP Implementation

2 FTP Model User Interface User Server PI User PI File System Server DTP
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 DTP: Data Transfer Process Jin Pyo Hong, HUFS

3 FTP Commands for Minimum Implementation
User Cmd FTP Cmd arguments 비고 open <hostname> Connect to FTP server [user] USER <username> User name PASS <password> Password nlist NLST [<pathname>] Name list (ls) ls, dir LIST Directory list (ls –l) pwd PWD Print working directory cd CWD <pathname> Change working directory lcd Change local working directory type [type] ascii [type] binary TYPE A I FTP data type ? A – NVT-ASCII text I – binary data get RETR Retrieve: download the file put STOR Store: upload the file passive Passive mode on or off (toggle switch) If passive mode on, send PASV for data transfer Otherwise, send PORT PASV Set server into passive mode. Server will reply 227 response with its IP and port PORT h1,h2,h3,h4,p1,p2 Data port for FTP client h1,h1,h3,h4: IPv4 address p1,p2: port number close QUIT Close FTP session bye, quit Close FTP session and exit Jin Pyo Hong, HUFS Jin Pyo Hong, HUFS

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 Jin Pyo Hong, HUFS

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). Jin Pyo Hong, HUFS

6 Open and Closing FTP Sessions
User Interface User PI Server PI open <host> or from argv 설계: State transition diagram - Event: User command, Reply msg Action: send FTP command … * reply msg에 대한 state transition도 포함해야 Establish Control Connection 220 Service ready <user name> USER <user name> <password> 331 Need passwd State transition table을 만든다면, if-then-else를 쓰지 않고, table-driven programming할 수 있지 않을까? PASS <password> 230 User logged in Data Transfer close bye, quit QUIT Jin Pyo Hong, HUFS 221 Service closing

7 Data Transfer: get, put, ls - passive mode on
Server PI Server DTP User Interface User DTP User PI get/put/ls <file> IP addr, port of server DTP (server’s listening socket addr) PASV 227 Entering Passive Mode (203,253,69,113,201,131) RETR/STOR/LIST <file> Establish data connection 150 Opening data connection Data Transfer Close connection 226 Transfer Complete Jin Pyo Hong, HUFS

8 Data Transfer: get, out, ls - passive mode off
Server PI Server DTP User Interface User DTP User PI User logged in 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, … ); get PORT h1,h2,h3,h4,p1,p2 200 Command Successful RETR/STOR/LIST <file> Establish data connection 150 Opening data connection Data Transfer Close connection 226 Transfer Complete Jin Pyo Hong, HUFS

9 State Transition Diagram
CWD, QUIT, PORT, PWD, TYPE Error 1yz 3yz Send cmd 2yz Begin Wait for reply Success 4yz 5yz Failure Jin Pyo Hong, HUFS

10 State Transition Diagram
LIST, NLST, RETR, STOR Error 3yz Send cmd 2yz Begin Wait for reply Success 1yz 4yz 5yz Failure Jin Pyo Hong, HUFS

11 State Transition Diagram
Login Sequence: USER, PASS Send USER Begin User ID sent 1 Error 2 3 4, 5 Send PASS 1,3 Wait for reply Success Enter passwd 2 4, 5 Failure Jin Pyo Hong, HUFS

12 Reference RFC959, File Transfer Protocol (FTP) Jin Pyo Hong, HUFS


Download ppt "Tips on FTP Implementation"

Similar presentations


Ads by Google