1 Tips for the assignment
2 Socket: a door between application process and end- end-transport protocol (UDP or TCP) TCP service: reliable transfer of bytes from one process to another process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server Internet Socket Programming using TCP
3
4 client Client socket server Welcome socket Connection socket time Client socket bytes Client Sockets & Server Sockets
5 Client/server socket interaction: TCP wait for incoming connection request connectionSocket = accept() create socket, port= x, for incoming request: welcomeSocket = Socket() create socket, connect to hostid, port= x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server Server (running on hostid ) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup Application 2-5
6 socket bind listen loop "forever" { accept /* by creating new socket */ /* process the client’s request */ loop until done { receive/send } closesocket(newsocket) } Simple Server Pseudo-Code
7 socket connect /* process the client’s request */ loop until done { send/receive } closesocket(socket) Simple Client Pseudo-Code
8 socket bind listen loop "forever" { accept /* by creating new socket */ /* process the clients request */ loop until done { receive/send } closesocket(newsocket) } Proper Ordering of Send and Recv socket connect /* process the clients request */ loop until done { send/receive } closesocket(socket)
9 Test the TCP Client-Server Codes ServerWindows.c Run ServerWindows.c ClientWindows.c Compile ClientWindows.c, look for the executable. ClientWindows.c Run ClientWindows.c from the command prompt to connect to the server: ClientWindows localhost 1234 Alternatively, use IpConfig to find out what your IP address is: (e.g ), then connect to the server using: ClientWindows ClientWindows Let’s see how to use the compiler’s debug mode to trace the exchange of messages.
10
11 FTP (Multiple Clients) In TCP, the Server should be running already prior to a Client connecting to it S Server TCP Control Socket C ListeningSocket DIR TCP Active Data Socket Port 127,0,0,1,6,11 Quit After file transfer
12
13 FTP Operation Source: Computer Networking and the Internet (5/e) by Fred Halsall CLIENT SERVER Control connection Data connection Note that Ports 1216 & 1217 are ephemeral ports. Any port [1024, 65535] will work.
14 FTP Commands COMMANDDESCRIPTION USER usernameUser name on the FTP server PASS passwordUser’s password on the FTP server SYSTType of operating system requested TYPE typeFile type to be transferred: A (ASCII), I (Image/Binary) PORT n1,n2,n3,n4,n5,n6Client IP address (n1-n4) and port number (n5, n6) RETR filename.typeRetrieve (get) a file STOR filename.typeStore (put) a file LIST filelistList files or directories QUITLog off from server Source: Computer Networking and the Internet (5/e) by Fred Halsall
15 FTP Reply Codes REPLYDESCRIPTION 1 1yzPositive reply, wait for another reply before sending a new command 2 2yzPositive reply, a new command can be sent 3 3yzPositive reply, another command is awaited 4 4yzNegative reply, try again 5 5yzNegative reply, do not retry 0x0z0x0zSyntax 1x1z1x1zInformation 2x2z2x2zControl or data connection 3x3z3x3zAuthentication 4x4z4x4zUnspecified 5x5z5x5zFile status Source: Computer Networking and the Internet (5/e) by Fred Halsall
16 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.
17 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.
18 p. 50, RFC 959
19 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Port1120Port1121 Data connectioncontrol connection
20 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open Port1120Port1121 Data connectioncontrol connection
21 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established Port1120Port1121 Data connectioncontrol connection
22 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready Port1120Port1121 Data connectioncontrol connection
23 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER Port1120Port1121 Data connectioncontrol connection
24 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required Port1120Port1121 Data connectioncontrol connection
25 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS Port1120Port1121 Data connectioncontrol connection
26 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in Port1120Port1121 Data connectioncontrol connection
27 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in SYST Port1120Port1121 Data connectioncontrol connection
28 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in SYST 215 UNIX Type:X Version:Y Port1120Port1121 Data connectioncontrol connection
29 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in get Port1120Port1121 Data connectioncontrol connection
30 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 get Port1120Port1121 Data connectioncontrol connection
31 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get Port1120Port1121 Data connectioncontrol connection
32 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR Port1120Port1121 Data connectioncontrol connection
33 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Port1120Port1121 Data connectioncontrol connection
34 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Server does an active open to Port n5, n6 Port1120Port1121 Data connectioncontrol connection
35 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Send file through data connection Server does an active open to Port n5, n6 Port1120Port1121 Data connectioncontrol connection
36 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Send file through data connection Server does an active open to Port n5, n6 226 File transfer complete User prompted for a conmand Port1120Port1121 Data connectioncontrol connection
37 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Send file through data connection Server does an active open to Port n5, n6 226 File transfer complete User prompted for a conmand QUIT Port1120Port1121 Data connectioncontrol connection
38 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Send file through data connection Server does an active open to Port n5, n6 226 File transfer complete, User prompted for a conmand QUIT 221 Goodbye Port1120Port1121 Data connectioncontrol connection
39 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER Port20Port21 Data connection control connection Port1120Port1121 Data connectioncontrol connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PORT n1-n6 200 PORT command successful get RETR 150 opening ASCII mode data connection Send file through data connection Server does an active open to Port n5, n6 226 File transfer complete, User prompted for a conmand QUIT 221 Goodbye Server closes data connection first, then control connection
40
41 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Port1120Port1121 Data connection control connection
42 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open Port1120Port1121 Data connection control connection
43 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established Port1120Port1121 Data connection control connection
44 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready Port1120Port1121 Data connection control connection
45 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER Port1120Port1121 Data connection control connection
46 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection Data connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required Port1120Port1121 Data connection control connection
47 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS Port1120Port1121 Data connection control connection
48 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in Port1120Port1121 Data connection control connection
49 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection Port1120Port1121 time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in SYST Data connection control connection
50 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in SYST 215 UNIX Type:X Version:Y Port1120Port1121 Data connection control connection
51 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV Port1120Port1121 Data connection control connection
52 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port 2024 Port1120Port1121 Data connection control connection
53 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port 2024 dir Port1120Port1121 Data connection control connection
54 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port 2024 LIST dir Port1120Port1121 Data connection control connection
55 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port 2024 LIST dir 150 Opening ASCII mode data connection for file list Port1120Port1121 Data connection control connection
56 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port n5, n6 (or Port 2024 in this example) LIST dir 150 Opening ASCII mode data connection for file list Client does an active open to Port n5,n6 Port1120Port1121 Data connection control connection
57 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port n5, n6 (or Port 2024 in this example) LIST dir 150 Opening ASCII mode data connection for file list Client does an active open to Port n5,n6 Send file through data connection Port1120Port1121 Data connection control connection
58 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port n5, n6 (or Port 2024 in this example) LIST dir 150 Opening ASCII mode data connection for file list Client does an active open to Port n5,n6 Send file through data connection 226 File transfer complete User is prompted for a command Port1120Port1121 Data connection control connection
59 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port n5, n6 (or Port 2024 in this example) LIST dir 150 Opening ASCII mode data connection for file list Client does an active open to Port n5,n6 Send file through data connection 226 File transfer complete User is prompted for a command QUIT Port1120Port1121 Data connection control connection
60 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port n5, n6 (or Port 2024 in this example) LIST dir 150 Opening ASCII mode data connection for file list Client does an active open to Port n5,n6 Send file through data connection 226 File transfer complete User is prompted for a command QUIT 221 Goodbye Port1120Port1121 Data connection control connection
61 Source: Computer Networking and the Internet (5/e) by Fred Halsall PASSIVE FTP Operation CLIENTSERVER Port2024Port21 Data connection control connection time Passive open Active open TCP control connection to Port 21 established 220 FTP server ready USER 331 password required PASS 220 user logged in PASV 227 Entering PASV mode (192,168,150,90,195,149) Port n5, n6 (or Port 2024 in this example) LIST dir 150 Opening ASCII mode data connection for file list Client does an active open to Port n5,n6 Send file through data connection 226 File transfer complete User is prompted for a command QUIT 221 Goodbye Server closes data connection first, then control connection Port1120Port1121 Data connection control connection
62 Source: Computer Networking and the Internet (5/e) by Fred Halsall ACTIVE FTP Operation CLIENTSERVER
63 Security Issues Passive mode FTP servers Firewall administrators may not want to use Passive mode FTP servers because the FTP server can open any ephemeral port number. ephemeral port range Many FTP servers are configured with an ephemeral port range of 1024 through unsecured Firewall configurations that allow full access to all ephemeral ports for unsolicited connections may be considered unsecured.
64 Active Connections Proto Local Address Foreign Address State TCP IT027049:http IT massey.ac.nz:0 LISTENING TCP IT027049:epmap IT massey.ac.nz:0 LISTENING TCP IT027049:https IT massey.ac.nz:0 LISTENING TCP IT027049:microsoft-ds IT massey.ac.nz:0 LISTENING TCP IT027049:1025 IT massey.ac.nz:0 LISTENING TCP IT027049:1179 IT massey.ac.nz:0 LISTENING TCP IT027049:1181 IT massey.ac.nz:0 LISTENING TCP IT027049:1300 IT massey.ac.nz:0 LISTENING TCP IT027049:1318 IT massey.ac.nz:0 LISTENING TCP IT027049:1786 IT massey.ac.nz:0 LISTENING TCP IT027049:1787 IT massey.ac.nz:0 LISTENING TCP IT027049:1790 IT massey.ac.nz:0 LISTENING TCP IT027049:1791 IT massey.ac.nz:0 LISTENING TCP IT027049:5000 IT massey.ac.nz:0 LISTENING TCP IT027049:13450 IT massey.ac.nz:0 LISTENING TCP IT027049:netbios-ssn IT massey.ac.nz:0 LISTENING TCP IT027049:1082 IT massey.ac.nz:0 LISTENING TCP IT027049:1179 its-xchg4.massey.ac.nz:1165 ESTABLISHED TCP IT027049:1181 its-dc2.massey.ac.nz:1025 ESTABLISHED TCP IT027049:1318 hnt-up-dhcp-494.wharton.upenn.edu:62686 ESTABLISHED TCP IT027049:1456 IT massey.ac.nz:0 LISTENING TCP IT027049:1456 alb-file2.massey.ac.nz:netbios-ssn ESTABLISHED TCP IT027049:1467 IT massey.ac.nz:0 LISTENING TCP IT027049:1467 itsa-campus1.massey.ac.nz:netbios-ssn ESTABLISHED TCP IT027049:1786 d home.cgocable.net:7091 ESTABLISHED Some utility: Netstat COMMAND: Netstat -a Displays all active TCP connections and the TCP and UDP ports on which the computer is listening
65 TCP IT027049:1787 pcp pcs.detrtc01.mi.comcast.net:21848 ESTABLISHED TCP IT027049:1790 balticom balticom.lv:63567 ESTABLISHED TCP IT027049: nyc.rr.com:1236 ESTABLISHED TCP IT027049:8947 IT massey.ac.nz:0 LISTENING UDP IT027049:microsoft-ds *:* UDP IT027049:isakmp *:* UDP IT027049:1026 *:* UDP IT027049:1027 *:* UDP IT027049:1028 *:* UDP IT027049:1046 *:* UDP IT027049:1088 *:* UDP IT027049:1177 *:* UDP IT027049:13450 *:* UDP IT027049:38037 *:* UDP IT027049:ntp *:* UDP IT027049:1187 *:* UDP IT027049:1459 *:* UDP IT027049:1718 *:* UDP IT027049:1900 *:* UDP IT027049:ntp *:* UDP IT027049:netbios-ns *:* UDP IT027049:netbios-dgm *:* UDP IT027049:1900 *:* UDP IT027049:8760 *:* UDP IT027049:62493 *:*
66 How to change the Internet Explorer FTP Client mode Start Internet Explorer. On the Tools menu, click Internet Options. Click the Advanced tab. Under Browsing, click to clear the Enable folder view for FTP sites check box. Passive FTP Click to select the Use Passive FTP (for firewall and DSL modem compatibility) check box. Internet Explorer behaves as a Standard mode FTP client if you select the Enable folder view for FTP sites check box, even if you also select the Use Passive FTP check box. If you clear the Enable folder view for FTP sites check box and then select the Use Passive FTP check box, Internet Explorer behaves as a Passive mode FTP client.
67 The End