640 likes | 763 Views
FTP Protocol Details. Tips for the assignment. Socket Programming using TCP. controlled by application developer. controlled by application developer. process. process. socket. socket. TCP with buffers, variables. controlled by operating system. TCP with buffers, variables.
E N D
FTP Protocol Details Tips for the assignment
Socket Programming using TCP controlled by application developer controlled by application developer process process socket socket TCP with buffers, variables controlled by operating system TCP with buffers, variables controlled by operating system Internet host or server host or server Socket: a door between application process and end-end-transport protocol (UDP or TCP) TCP service: reliable transfer of bytesfrom one process to another
Client Sockets & Server Sockets server client Client socket Welcome socket time Client socket Connection socket bytes
Client/server socket interaction: TCP create socket, connect to hostid, port=x create socket, port=x, for incoming request: clientSocket = Socket() welcomeSocket = Socket() TCP connection setup wait for incoming connection request connectionSocket = accept() send request using clientSocket read request from connectionSocket write reply to connectionSocket read reply from clientSocket close connectionSocket close clientSocket Server(running on hostid) Client Application 2-5
Simple Server Pseudo-Code socket bind listen loop "forever" { accept /* by creating new socket */ /* process the client’s request */ loop until done { receive/send } closesocket(newsocket) }
Simple Client Pseudo-Code socket connect /* process the client’s request */ loop until done { send/receive } closesocket(socket)
Proper Ordering of Send and Recv socket connect /* process the clients request */ loop until done { send/receive } closesocket(socket) socket bind listen loop "forever" { accept /* by creating new socket */ /* process the clients request */ loop until done { receive/send } closesocket(newsocket) }
Test the TCPClient-Server Codes • Run ServerWindows.c • Compile ClientWindows.c, look for the executable. • Run ClientWindows.c from the command prompt to connect to the server: • ClientWindowslocalhost1234 • Alternatively, use IpConfig to find out what your IP address is: (e.g. 130.123.123.111), then connect to the server using: • ClientWindows130.123.123.1111234 • Let’s see how to use the compiler’s debug mode to trace the exchange of messages.
FTP (Multiple Clients) TCP Control Socket C DIR Port 127,0,0,1,6,11 Listening Socket After file transfer TCP Control Socket Quit S TCP Active Data Socket Server • In TCP, the Server should be running already prior to a Client connecting to it
FTP Operation CLIENT SERVER Control connection Data connection Note that Ports 1216 & 1217 are ephemeral ports. Any port [1024, 65535] will work. Source: Computer Networking and the Internet (5/e) by Fred Halsall
FTP Commands Source: Computer Networking and the Internet (5/e) by Fred Halsall
FTP Reply Codes Source: Computer Networking and the Internet (5/e) by Fred Halsall
Active FTP (or Standard ) Standard (or PORT or Active) The Standard mode FTP client sends PORT commands to the FTP server. These commands are sent over the FTP command channel when establishing the FTP session. Operation Standard mode FTP clients first establish a connection to TCP port 21 on the FTP server. This connection establishes the FTP command channel. The client sends a PORT command over the FTP command channel when the FTP client needs to send or receive data, such as a folder list or file. The PORT command contains information about which port the FTP client receives the data connection on. In Standard mode, the FTP server always starts the data connection from TCP port 20. The FTP server must open a new connection to the client when it sends or receives data, and the FTP client requests this by using the PORT command again.
Passive FTP (or PASV) Passive (or PASV) The Passive mode client sends PASV commands to the FTP Server. Operation Passive mode FTP clients also start by establishing a connection to TCP port 21 on the FTP server to create the control channel. When the client sends a PASV command over the command channel, the FTP server opens an ephemeral port (between 1024 and 5000) and informs the FTP client to connect to that port before requesting data transfer. As in Standard mode, the FTP client must send a new PASV command prior to each new transfer, and the FTP server will await a connection at a new port for each transfer.
Active FTP mode p. 50, RFC 959
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Passive open time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in SYST time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in SYST 215 UNIX Type:XVersion:Y time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in get <filename.type> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful RETR <filename.type> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful RETR <filename.type> 150 opening ASCII mode data connection time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful Server does an active open to Port n5, n6 RETR <filename.type> 150 opening ASCII mode data connection time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful Server does an active open to Port n5, n6 RETR <filename.type> 150 opening ASCII mode data connection Send file through data connection time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful Server does an active open to Port n5, n6 RETR <filename.type> 150 opening ASCII mode data connection Send file through data connection 226 File transfer complete User prompted for a conmand time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful Server does an active open to Port n5, n6 RETR <filename.type> 150 opening ASCII mode data connection Send file through data connection 226 File transfer complete QUIT User prompted for a conmand time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful Server does an active open to Port n5, n6 RETR <filename.type> 150 opening ASCII mode data connection Send file through data connection 226 File transfer complete, QUIT User prompted for a conmand 221 Goodbye time Source: Computer Networking and the Internet (5/e) by Fred Halsall
ACTIVE FTP Operation SERVER CLIENT control connection control connection Data connection Data connection Port 20 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in PORT n1-n6 get <filename.type> 200 PORT command successful Server does an active open to Port n5, n6 RETR <filename.type> 150 opening ASCII mode data connection Send file through data connection 226 File transfer complete, QUIT User prompted for a conmand Server closes data connection first , then control connection 221 Goodbye time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVEFTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Passive open time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVEFTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in SYST time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall
PASSIVE FTP Operation SERVER CLIENT control connection Data connection Data connection control connection Port 2024 Port 21 Port 1120 Port 1121 Active open Passive open TCP control connection to Port 21 established 220 FTP server ready USER <username> 331 password required PASS <password> 220 user <username> logged in SYST 215 UNIX Type:XVersion:Y time time time time Source: Computer Networking and the Internet (5/e) by Fred Halsall