2 File Transfer Protocol Copying a file from one host to anotherProblems in FTPTwo systems may use different file name conventionsTwo systems may have different ways to represent text and data.Two systems may have different directory structures.FTP establishes two TCP connections between client and server.One connection is used for data transfer [Port 20]Other connection for control information (commands and responses) [Port 21]Separation of commands and data transfer makes FTP more efficient. Commands are very simple.
3 Client has three components Server has two components Figure FTPClient has three componentsUser interface, Client control process, client data transfer process.Server has two componentsServer control process, server data transfer processControl connection is made between control processes; Control connection is maintained during entire interactive FTP session.Data connection is made between data transfer processes; Data connection is opened & then closed for each file transferred.
4 Control Connection Data connection Figure Using the control connectionControl ConnectionCreated in same way as other application programs.Connection remains open during the entire process.TOS in IP header is minimize delay, because this is an interactive connection between a user (human) and a server.User types commands and expects to receive responses without significant delay.Data connectionOpened when data are ready to transfer. Closed when it is not needed.TOS in IP header is maximize throughput.
5 Communication over control connection Figure Using the data connectionCommunication over control connectionUses ASCII character set.Each command or response is only one short line, so we need not worry about file format or file structure.Each line is terminated with a two-character (carriage return and line feed) end-of-line token.Communication over data connectionClient must define the type to be transferred, the structure of the data, and the transmission mode.Heterogeneity is solved by: file type, data structure, transmission mode.
6 File type ASCII file: Image file By default for transferring text files.Sender transforms the file from its own representation to ASCII charactersReceiver transforms the ASCII characters to its own representation.Image fileDefault format for transferring binary filesFile is sent as continuous streams of bits without any interpretation or encodingUsed for compiled programs or images.
7 File structure (default) Data structureFTP can transfer a file across the data connection using one of the following interpretations about structure of data:File structure (default)File has no structure.Continuous stream of bytesRecord structureFile is divided into records (or structs in C).Used only with text files.Page structureFile is divided into pages, with each page having a page number and a page header.Pages can be stored or accessed randomly or sequentially.
8 Transmission mode: FTP can transfer a file across the data connection by using one of following three transmission modes:Stream modeDefault modeData is delivered from FTP to TCP as a continuous stream of bytes; TCP is responsible for chopping data into segments of appropriate size.End-of-file is closing of data connection by sender.If data is divided into records, each record will have 1-byte end-of-record (EOR) character, and the end of the file will have a 1-byte end-of-file (EOF) character.Block modeData can be delivered from FTP to TCP in blocks.Block is preceded by 3-byte header.1st byte is called the block descriptor; next 2 bytes defines the size of block in bytes.Compressed modeIf file is big, data can be compressed.Commonly used compression method is run-length encoding.Consecutive appearance of a data unit are replaced by one occurrence and number of repetitions. Usually, Blanks in text file and null characters in binary file are compressed.
9 Figure File transferMeans of File TransferRetrieving a file: Copy file from server to client.Storing a file: copy file from client to server.List of directory or file names is to be sent from the server to the client. Note that FTP treats a list of directory or file names as a file. It is sent over the data connection.
10 Example 1Figure (next slide) shows an example of how a file is stored.The control connection is created, and several control commands and responses are exchanged.Data are transferred record by record.A few commands and responses are exchanged to close the connection.
13 Example 2We show some of the user interface commands that accomplish the same task as in Example 1. The user input is shown in boldface. As shown below, some of the commands are provided automatically by the interface. The user receives a prompt and provides only the arguments.$ ftp challenger.atc.fhda.eduConnected to challenger.atc.fhda.edu220 Server readyName: forouzanPassword: xxxxxxxftp > ls /usr/user/report200 OK150 Opening ASCII mode226 transfer completeftp > close221 Goodbyeftp > quit
14 Example 3We show an example of using anonymous [public access OR without an account] FTP. We connect to internic.net, where we assume there are some public data available.Sometimes, anonymous as user name and guest as password$ ftp internic.netConnected to internic.net220 Server readyName: anonymous331 Guest login OK, send "guest" as passwordPassword: guestftp > pwd257 '/' is current directoryftp > ls200 OK150 Opening ASCII modebin...ftp > close221 Goodbyeftp > quit