1 internet services. 2 telnet protocol 3 telnet allows a person sitting on one computer to work on...

Post on 27-Dec-2015

221 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Internet Services

2

TELNET Protocol

3

TELNET

• Allows a person sitting on one computer to work on another computer.

• Starts a remote session on another machine.• Requires a person to supply login name and

password to gain entry.• Command:

telnet <domain_name>

telnet <ip_address> A B

4

TELNET (contd.)

• Why required?– For using software only available on the remote

host.– For using devices (like printer) connected to the

remote host.

• Typical scenario– Many users do a telnet to a remote server, and

work there.– Server is a bigger and faster computer.

5

TELNET (contd.)

• By default connection is established over port 23.

• Any other port number can also be specified. telnet cse.iitkgp.ernet.in 25

6

A Sample TELNET Session

SUNNY>> telnet cseTrying 144.16.192.57...Connected to cse.Escape character is '^]'. Linux 1.2.8 (cse) (ttyp0)  cse login: isgPassword: Last login: Wed Jun 11 12:17:55 from 144.16.202.210Linux 1.2.8. (POSIX).You have new mail. cse:~$

7

FTP Protocol

8

File Transfer Protocol (FTP)

• Allows a person to transfer files between two machines.

• Requires a person to supply login name and password to gain entry.

• Command: ftp <domain_name>

ftp <ip_address>

9

Anonymous FTP

• A special form of FTP which has become very popular.– Does not require a person to know login name

and password.– In place of login name, type the word

anonymous.– In place of password, type the email address.

• Huge amount of resources are available in anonymous FTP sites.

10

FTP Process Model

Control

DataTransfer

Control

INTERNET

Port 21

DataTransfer

SERVERCLIENT

Port 22

11

How FTP Works?

• Two connections established:– A control connection over port 21, that

remains all through a session.– A temporary port number, used for every file

being transferred.• New connection established for every file

transfer.

12

Typical FTP Commands

• put, mput– Send one (or more) file(s).

• get, mget– Receive one (or more) file(s).

• hash– Indicates progress of file transfer.

• prompt– Prompts user before actual transfer of each file.

• bin, asc– Selects binary or ascii mode of transfer.

• exit– Terminates connection with ftp server.

13

Sample FTP Sessions

SUNNY>> ftp cseindigoConnected to cseindigo.220 cseindigo FTP server ready.Name (cseindigo:isg): isg331 Password required for isg.Password:230 User isg logged in.Remote system type is UNIX.Using binary mode to transfer files.ftp>

14

Sample FTP Sessions (contd.)

ftp> dir200 PORT command successful.150 Opening ASCII mode data connection for '/bin/ls'.total 97drwxr-xr-x 2 isg faculty 512 Oct 8 1995 PROJECTS-rw-r--r-- 1 isg faculty 7693 Mar 31 1995 lan-cse.fig-rw-r--r-- 1 isg faculty 6578 Apr 26 1995 lan-cse.fig-rw-r--r-- 1 isg faculty 6721 Jul 12 1995 newlan.fig226 Transfer complete.

15

Sample FTP Sessions (contd.)

ftp> get lan-cse.fig200 PORT command successful.150 Opening BINARY mode data connection for 'lan-cse.fig' (6721 bytes).226 Transfer complete.6721 bytes received in 0.0389 secs (1.7e+02 Kbytes/sec) ftp> quit221 Goodbye. SUNNY>>

16

Electronic Mail

Indian Institute of Technology Kharagpur

17

Electronic Mail

• Most widely used application on the Internet.

• For sending mails:– Simple Mail Transfer Protocol (SMTP)– Multi-purpose Internet Mail Extension (MIME)

• For receiving mails:– Post office protocol version 3 (POP3)– Internet mail access protocol (IMAP)

18

Simple Mail Transfer Protocol

• Based on RFC 821.• Transmits simple text messages only.

– 7-bit ASCII format.

• Uses information written on envelope of mail.– Message header.– Contains recipient address and other information.

• Does not look at contents.– Message body.

19

Message Header

Message Body

MailMessage

20

Basic Operation

• Mail is created by user agent program (mail client).– mailx, pine, Outlook, etc.

• Messages queued and sent as input to SMTP sender program.– Typically a server process.– Daemon on UNIX.

• sendmail or qmail• Listens on port number 25

21

SMTP Mail Flow

UserAgent

SMTPServer

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

User Mailboxes

SMTPServer

SMTPServer

Port 25

Port 25

Port 25

22

Mail Message Contents

• Each queued message has:– Message text

• RFC 822 header with message envelope and list of recipients.

• Message body, composed by user.– A list of mail destinations

• Derived by user agent / SMTP server from header.

• May require expansion of mailing lists.

23

SMTP Sender

• Takes message from queue.• Transmits to proper destination host.

– Via SMTP transaction.– Over one or more TCP connections to port 25.

• When all destinations have been processed, message is deleted.

24

Optimization

• If message is sent to multiple users on a given host, it is sent only once.– Delivery to users handled at destination host.

• If multiple messages are ready for given host, a single TCP connection can be used.– Saves overhead of setting up and dropping

connection.

25

Possible Errors

• Host unreachable• Host out of operation• TCP connection fail during transfer• Faulty destination address

– User error– Target user address has changed– Redirect if possible– Inform user if not

26

SMTP Protocol - Reliability

• Used to transfer messages from sender to receiver over TCP connection.– Uses port number 25.

• Attempts to provide reliable service.• No guarantee to recover lost messages.• No end-to-end ACK to sender.• Error indication report not guaranteed.

27

SMTP Receiver

• Accepts arriving message.• Places in user mailbox or copies to

outgoing queue for forwarding.• Receiver must:

– Verify local mail destinations.– Deal with errors

• Transmission• Lack of disk space

28

SMTP Forwarding

• Mostly direct transfer from sender host to receiver host.

• May go through intermediate mail servers via forwarding capability.– Sender can specify route.

29

SMTP Mail Flow

UserAgent

SMTPServer

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

Header

MailBody

User Mailboxes

SMTPServer

SMTPServer

Port 25

Port 25

Port 25

30

SMTP System Overview

• Commands and responses exchanged between sender and receiver.

• Initiative with sender.– Establishes TCP connection.

• Sender sends commands to receiver.– e.g. HELO <domain><CRLF>

• Each command generates exactly one reply.– e.g. 250 requested mail action ok; completed.

31

SMTP Replies

• Starts with 3-digit code.• Leading digit indicates category.

– 2xx -- Positive completion reply– 3xx -- Positive intermediate reply– 4xx -- Transient negative completion reply – 5xx -- Permanent negative completion reply

32

Operation Phases

a) Connection setup

b) Exchange of command-response pairs

c) Connection termination

33

a) Connection Setup

• Sender opens TCP connection with receiver.• Once connected, receiver identifies itself.

220 <domain> service ready• Sender identifies itself.

HELO• Receiver accepts sender’s identification.

250 OK• If mail service not available, the response to the

second step above becomes: 421 service not available

34

b) Mail Transfer Commands

• The MAIL FROM command identifies originator.– Gives reverse path to be used for error

reporting.– Receiver returns 250 OK or appropriate failure /

error message.

35

• One or more RCPT TO commands identify recipients for the message.– Separate reply for each recipient.

• The DATA command transfers message text.– End of message indicated by a line containing

just period (.)

36

c) Closing Connection

• Two steps:– Sender sends QUIT and waits for reply.– Then initiate TCP close operation.

• Receiver initiates TCP close after sending reply to QUIT.

37

An Example SMTP Session

• How to connect to an SMTP server? telnet servername 25

– A TCP connection gets established over port number 25.

– The telnet client and the mail server can now start a dialogue.

38

An Example SMTP Session

S: 220 hotmail.com Simple Mail Transfer Service ReadyC: HELO yahoo.comS: 250 hotmail.com

C: MAIL FROM: <isg@yahoo.com> S: 250 OK

C: RCPT TO: <myfriend@hotmail.com> S: 250 OK

C: RCPT TO: <somebody@rediffmail.com> S: 250 OK

39

An Example SMTP Session

C: DATA

S: 354 Start mail input; end with (.)

C: … actual contents of the message …

C: ………

C: ………

C: .S: 250 OK

C: QUIT

S: 221 hotmail.com Service closing transmission channel

40

Mail Access Protocols

• Two mail access protocols are widely used:1. Post Office Protocol, version 3 (POP3)

2. Internet Mail Access Protocol version 4 (IMAP4).

41

What do they do?

User Mailboxes

on SMTP server

Mail Client

POP3 / IMAP

42

POP3

• The client POP3 software is installed on the recipient machine, and the server POP3 software installed on mail server.– The client (user agent) opens a connection

with the server on TCP port number 110.– Sends user name and password.– Can access the mails, one by one.

43

POP3 (contd.)

– Two modes:• Delete mode – mails deleted as they are read• Keep mode – mails remain in the mailbox

– POP3 has commands for:• Log in• Log out• Fetch messages• Delete messages

44

IMAP4

• Provides the following extra features:– A user can check the email header before

downloading.– A user can search the contents of the email for

a specific string prior to downloading.– A user can create, delete, or rename mailboxes

on the mail server.– A user can create a hierarchy of mailboxes in a

folder for email storage.

45

Multipurpose Internet Mail Extension (MIME)

• SMTP cannot transmit non-text messages.– Solutions (like uuencode) exists on some

systems, but are not standardized.

• Cannot transmit text that includes international characters (e.g. â, å, ä, è, é, ê, ë).– Need 8 bit ASCII.

46

• Servers may reject mail over certain size.• Some SMTP implementations do not

adhere to standard.– CRLF, truncate or wrap long lines, removal of

white space, etc.

47

Overview of MIME

• Five new message header fields:– MIME-version– Content-type– Content-transfer-encoding– Content-Id– Content-description

• A number of content types and transfer encoding formats have been defined.

48

Content Types

• Text body• Multipart

– Mixed, Parallel, Alternative

• Message– RFC 822, Partial,

External-body• Image

– jpeg, gif

• Video– mpeg

• Audio– Basic

• Application– Postscript– octet stream

49

MIME Transfer Encodings

• Specifies how the mail body is wrapped for transmission.

• Content transfer encoding field can have six possible values.– 7bit, 8bit, binary:

• No encoding done for these three.

• Provide information about nature of data.

50

– Quoted-printable• Data mostly printable ASCII characters.• Non-printing characters represented by hex code.

– Base64• Maps arbitrary binary input onto printable output.

– X-token• Named nonstandard encoding.

51

Base64 Encoding

6 bits 6 bits 6 bits6 bits

8 bits8 bits 8 bits 8 bits

R64 R64 R64 R64

• Expands the message by 33%.

• Uses the symbols A..Z, a..z, 0..9, +, /

52

MIME Header ExampleFrom: Indranil Sengupta <isg@iitkgp.ac.in>To: Jaswinder Ahuja <jassi@cadence.com>Subject: Simple MessageMIME-Version: 1.0Content-type: multipart/mixed; boundary="simple boundary"

This is the preamble. It is to be ignored, though it is a handy place for mail composers to include an explanatory note.--simple boundary

This is implicitly typed plain text. It does NOT end with a linebreak.-- simple boundaryContent-type: text/plain; charset=us-ascii

This is explicitly typed plain ASCII text. It DOES end with a linebreak.

--simple boundary--This is the epilogue. It is also to be ignored.

53

Another MIME ExampleFrom: Indranil Sengupta <isg@iitkgp.ac.in>To: Jaswinder Ahuja <jassi@cadence.com>Subject: Formatted text mailMIME-Version: 1.0Content-type: multipart/alternative; boundary=boun42

--boun42

Content-type: text/plain; charset=us-ascii

... plain text version of message goes here ...

--boun42Content-type: text/enriched

... RFC1896 text/enriched version of the same message goes here

...--boun42--

54

World Wide Web

Indian Institute of Technology Kharagpur

55

World Wide Web (WWW)

• Latest revolution in the internet scenario.• Allows multimedia documents to be

shared between machines.– Containing text, image, audio, video,

animation.

• Basically a huge collection of inter-linked documents.– Billions of documents.– Inter-linked in any possible way.– Resembles a cob-web.

56

WWW (contd.)

• Where do the documents reside?– On web servers.– Also called Hyper Text Transfer Protocol

(HTTP) servers.

• They are typically written in– Hyper Text Markup Language (HTML).

• Documents get formatted/displayed using– Web browsers

• Internet Explorer• Netscape• Mosaic• Konquerer

57

What is HTTP?

• Hyper Text Transfer Protocol– A protocol using which web clients (browsers)

interact with web servers.

• It is a stateless protocol.– Fresh connection for every item to be

downloaded.

• Transfers hypertext across the Internet.– A text with links to other text documents.– Resembles a cob-web, and hence the name

World Wide Web (WWW).

58

HTTP Protocol

• Web clients (browsers) and web servers communicate via HTTP protocol.

• Basic steps:– Client opens socket connection to the HTTP

server.• Typically over port 80.

– Client sends HTTP requests to server.– Server sends back response.– Server closes connection.

• HTTP is a stateless protocol.

59

Illustration

Web Servers

WebClient

http request

http response

http request

http response

60

HTTP Request Format

• A client request to a server consists of:– Request method– Path portion of the HTTP URL– Version number of the HTTP protocol– Optional request header information– Blank line– POST or PUT data if present.

61

HTTP Request Methods

• GET– Most common HTTP method.– Returns the contents of the specified

document.– Places any parameters in request header.– Can also be used to submit forms:

• The form data is URL-encoded and appended to the GET command URL.

62

Illustration of GET

– A very simple HTTP connection to a server. telnet www.facweb.iitkgp.ac.in http

– Client sends request for a file: GET /test.html HTTP/1.0

– The server sends back the response: HTTP/1.1 200 OK Date: Sun, 22 May 2005 09:51:42 GMT Server: Apache/1.3.33 (Win32) Last-Modified: Sun, 22 May 2005 09:51:10 GMT Accept-Ranges: bytes Content-Length: 119 Connection: close

63

Illustration of GET (contd.)

Content-Type: text/html

<html> <head> <title> A test page </title> </head>

<body>

This is the body of the test page.

</body>

</html>

64

HTTP Request Methods (contd.)

• HEAD– Returns only the header information of the

specified document.– Used by clients to determine the file size,

modification date, server version, etc.

65

Illustration of HEAD

• Client sendsHEAD /index.html HTTP/1.0

• Server responds back with:HTTP/1.1 200 OK

Date: Sun, 22 May 2005 10:08:37 GMT

Server: Apache/1.3.33 (Win32)

Last-Modified: Thu, 03 May 2001 11:30:38 GMT

Accept-Ranges: bytes

Content-Length: 1494

Connection: close

Content-Type: text/html

66

HTTP Request Methods (contd.)

• POST– Used to send data to the server to be processed in

some way, as in a CGI script.– Basic difference from GET:

• A block of data is sent along with the request. Extra headers like Content-Type and Content-Length are used for this purpose.

67

• The requested object is not a resource to retrieve. Rather, it is a script that can handle the data being sent.

• The server response is not a static file; but is generated dynamically as the program output.

68

Illustration of POST

– A typical form submission, using POST is illustrated below:

POST /cgi-bin/myscript.cgi HTTP/1.0

From: isg@hotmail.com

User-Agent: HTTPTool/1.0

Content-Type: application/x-www-form-urlencoded

Content-Length: 32

Roll=1234&Sex=M&Age=20

69

HTTP Request Methods (contd.)

• PUT– Replaces the contents of the specified

document with data supplied along with the command.

– Not used widely.

• DELETE:– Deletes the specified document from the

server.– Not used widely.

70

HTTP Request Headers

• After a HTTP request line, a client can send any number of header fields.– Usually optional – used to convey some

information.– Some commonly used fields:

• Accept: MIME types client accepts, in order of preference.

• Connection: connection options, close or Keep-Alive.

71

• Content-Length: number of bytes of data to follow.

• Content-Type: MIME type and subtype of the data that follows.

• Pragma: “no-cache” option directs the server/proxy to return a fresh document even though a cached copy may exist.

72

HTTP Request Data

• To be given if the request type is either PUT or POST.– Send the data immediately after the HTTP

request header, and a blank line.

73

HTTP Response

• An initial response line.– Also called the status line.– Consists of three parts separated by spaces

• The HTTP version• A 3-digit response status code• An English phrase describing the status code.

HTTP/1.0 200 OK

HTTP/1.0 404 Not Found

74

HTTP Response (contd.)• Header information, followed by a blank

line, and then the data.

HTTP/1.1 200 OKDate: Sun, 22 May 2005 09:51:42 GMTServer: Apache/1.3.33 (Win32)Last-Modified: Sun, 22 May 2005 09:51:10 GMTContent-Length: 119Connection: closeContent-Type: text/html

<html> <head> <title> A test page </title> </head><body> This is the body of the test page.</body> </html>

75

3-digit Status Code

• 1xx– Indicates informational messages only.

• 2xx– Indicates successful transaction.

• 3xx– Redirects the client to another URL.

• 4xx– Indicates client error, such as unauthorized

request.

• 5xx– Indicates internal server error.

76

Common Status Codes

• 200 OK• 301 Moved Permanently• 302 Moved Temporarily• 401 Unauthorized• 403 Forbidden• 404 Not Found• 500 Internal Server Error

77

HTTP Response Headers

• Common response headers include:– Content-Length

• Size of the data in bytes.

– Content-Type• MIME type and subtype of data being sent.

– Date• Current date.

– Expires• Date at which document expires.

– Last-Modified– Set-Cookie

• Name/value pair to be stored as cookie.

78

HTTP Response Data

• A blank line follows the response header, and the data follows next.– No upper limit on data size.

• HTTP/1.0– Server typically closes connection after

completing a transaction.

• HTTP/1.1– Server keeps the connection open by default,

across transactions.

79

HTTP version 1.1

• Current standard and widely used.– Became IETF draft standard in 2001.

• Improvements over HTTP 1.0:– Requires host identification.

• Allows multi-homed servers.• More than one domain living on same server.

GET /index.html HTTP/1.1Host: www.facweb.iitkgp.ac.in<blank line>

80

HTTP version 1.1 (contd.)

– Default support for persistent connections.• Multiple transactions over a single connection.

– Support for content negotiation.• Decides on the best among the available representations.• Server-driven or browser-driven.

– Browsers can request part of document.• Specify the bytes using Range header.• Browser can ask for more than one range.• Continue interrupted downloads.

Range: bytes=1200-3500

81

HTTP version 1.1 (contd.)

– Efficient caching support• A document caching model that allows both

the server and the client to control the level of cachability and update conditions and requirements.

• HTTP 1.1 requires several extra things from both clients and servers.– Mandatory to know these if one is trying to

write a HTTP client or server.

82

HTTP 1.1 Client Requirements

• The clients must do the following:– Include the Host: header with each request.– Either support persistent connections, or include

the Connection: close header with each request.

– Handle the 100 Continue response.– Accept responses with chunked data.

83

HTTP 1.1 Server Requirements

• The servers must do the following:– Require the Host: header from HTTP 1.1 clients.– Accepts absolute URL’s in a request.– Accept requests with chunked data.– Include the Date: header in each response.– Support at least the GET and HEAD methods.– Support HTTP 1.0 requests.– Either support persistent connections, or include

the Connection: close header with each request.

84

How a Web Server Works?

85

Requirements of a Web Server

• Simple requirements:– Able to accept HTTP requests, and respond to

them.– Support for GET and HEAD, possibly also

POST.– Able to handle server-side scripts.

• Executables residing on the server.• They get executed when specified.• Their output sent back to the client;

typically as a HTML page.

86

Directory Structure

• When a web server is installed:– A http root directory gets created.

• For example, “/home/httpd”– There is a directory under the http root that

acts as the http home directory.• For example, “/home/httpd/docs”

– There is a directory under the http root under which all the CGI and other scripts are to be stored.

• For example, “/home/cgi-bin”• Server-side exec permission provided

87

Directory Structure (contd.)

HTTP Root

cgi-binHTTP Home Other

WebFolders

88

Default Web Page

• There is a default web page that gets returned by the server if no explicit document path is specified.– index.htm or index.html.– Any other name can also be specified through

server script configuration.

• Can be accessed as:GET www.xyz.com HTTP/1.0

89

How are Scripts Handled?

• Server-side scripts– A file that is to be executed by the server, and

the output sent back to the client.

• How does the server know?– Two ways:

• GET command with a “?”.• POST command.

90

GET Command with a “?”

• Consider an example HTTP command:GET /cgi-bin/xyz.pl ? roll=1234 & sex=M

• What happens?– Server identifies the “?” following the GET.– Identifies xyz.pl as a program to be executed.– Allows the xyz.com program to read the values

present in the string following the “?”.• How, to be discussed later

– The output generated by the xyz.com program is sent back to the client.

91

POST Command

• Works similar to get.• Differences:

– The name-value pairs are present as data following the header lines and a blank line.

– Not limited by the maximum size of a string (as in GET).

– The executable program can read the data values.

• How, to be discussed later.

92

POST Command :: Example

POST /cgi-bin/myscript.cgi HTTP/1.0

From: isg@hotmail.com

User-Agent: HTTPTool/1.0

Content-Type: application/x-www-form-urlencoded

Content-Length: 32

Roll = 1234 & Sex = M & Age = 20

93

Points to Note

• The executable program that runs on the server can be written in any language.– Shell script (C shell, bourne shell, etc.)– Perl– ASP– PHP– C, Java (requires servlet support)

• Necessary support for executing must be there in the server.

• For example, ASP can run under IIS but not under Apache.

top related