You are on page 1of 6

Computer Communication 352 (Index No.

4522)

CURTIN UNIVERSITY OF TECHNOLOGY


Department of Computing

Assignment

Simple File Transfer Protocol

Due Date: 4pm, Tuesday, Oct. 19, 2010

Objective:

The objective of this assignment is to develop two complementary programs (a


CLIENT, and a SERVER) that implement a simple file transfer protocol that
follows some of the FTP commands and replies specified in RFC 959.

Requirement:

1) FTP connection model

control connection Port 21


User FTP FTP
Interface Client Server

data connection Port 20

Local File
Remote
System
File System

The figure shows an FTP client (CLIENT) and an FTP server (SERVER) that are
connected by two parallel TCP connections: control connection and data connection.
The control connection is used for sending control information between the two
programs, e.g., user name/identification, password, and FTP command and
reply. The data connection is used to transfer the actual data between the two
programs. Note that the control connection is closed only when the FTP session
ends, while the data connection is closed each time the data transfer is completed.

For the control connection, the server listens (passive mode) on the well-known port
L=21; however, in your implementation you should use one of your assigned port
number, e.g., L=52001. The client initiates the control connection (active mode) to
the server on port L. On the other hand, for the data connection, the server uses
port number L−1 (e.g., 52000) that can be in a passive or an active mode. In other
words, if the client is in a passive mode on port U, the client should send the server
its port number U via the control connection so that the server can initiate the data
connection (active mode) to the port. If the client is in an active mode, the server is
Computer Communication 352 2nd Semester 2010

1
in the passive mode and must have created a socket and listen on port L−1 before
the client initiates the data connection to the server.

2) FTP commands and Replies

There is a one-to-one correspondence between each user interface command and


the FTP command sent across the control connection by the FTP client to the FTP
server. For each command, the server sends a reply in the form of a three-digit
number followed by a message. In this assignment, we consider only some of the
FTP command replies specified in RFC 959.

FTP Reply commands


125 Data connection already open; transfer starting.
150 File status okay; about to open data connection.
200 Command okay.
221 Service closing control connection.
Logout if appropriate.
226 Closing data connection.
Requested file action successful.
227 Entering passive mode.
250 Requested file action okay, completed.

425 Can’t open data connection.


450 Requested file action not taken.
File unavailable.
500 Syntax error, command unrecognized.
502 Command not implemented.

FTP commands
In this assignment, you are required to implement only the following commands.
Note that we do not follow all the FTP protocol in the following descriptions. The
client should print on its screen each message that it receives via the control
connection.

The FTP client recognizes the following user interface commands:

a. Get remotefile [localfile]: the client asks the server to transmit the
remotefile to the client.

Following RFC 959, the FTP client should send the following command to the FTP
server through the control connection:

RETR <SP> remotefile <CRLF>

For this command, assume the data connection in the server is in the passive
mode, and the protocol to create the data connection is done as follows.
Receiving the command, the server creates a passive socket on port L−1. Then,
it sends a reply command 227 to the client via the control connection. The client
Computer Communication 352 2nd Semester 2010

2
should create a new socket and connect it to the server on port L−1 (creating
the TCP data connection in the figure). As the reply, the server transmits the
remotefile to the client, closes its socket on the data connection, and sends a
reply command 226 to the client via the control connection. Receiving the file,
the client stores the file in its local directory/machine, and closes its socket on
the data connection. If the localfile is not specified, the default is
remotefile name (assume that the two machines use the same file naming
system). Your solution should consider both the binary and the text files.

b. put localfile [remotefile]: the client transmits localfile to the


server.

Following RFC 959, the FTP client sends the following command to the FTP server
via the control connection:

STOR <SP> remotefile <CRLF>

For this command, assume the data connection in the server is in the active
mode, and the protocol to create the data connection is done as follows. The
server sends a reply command 150 to the client via the control connection. The
client creates a passive socket on port number hostport, and sends it to
server through the control connection:

PORT <SP> hostport <CRLF>

Receiving the command, the server sends a reply command 200 via the control
connection, creates a new socket and binds it to port L−1, and connects to the
client on port number hostport (creating the TCP data connection in the
figure). Then, the server sends a reply command 125 to the client via the
control connection. Receiving this message, the client transmits the contents of
the localfile to the server through the data connection. Receiving the file,
the server closes its socket on the data connection, stores the file in its
directory/machine, and sends a reply command 226 to the client via the
control connection. The client then closes its socket on the data connection. If
the remotefile is not specified, the default is localfile name (assume
that the two machines use the same file naming system). Your solution should
consider both the binary and the text files.

c. dir: The server sends to the client its working directory list. Receiving the
list, the client shows it on its screen.

Let the FTP client send the following command to the FTP server via the control
connection:

LIST <CRLF>

For this command, assume the data connection in the server is in the active
mode. Use a similar protocol in part 2b.
Computer Communication 352 2nd Semester 2010

3
d. delete remotefile: The client asks the server to delete the file
remotefile which is stored in the server’s directory/machine.

RFC 959 requires the FTP client to send the following command to the FTP server
through the control connection:

DELE <SP> remotefile <CRLF>

After deleting the file, the server sends reply command 250 to the client
through the control connection.

e. quit: The client lets the server know that it is terminating the FTP session with the
server.

RFC 959 requires the FTP client to send the following command to the FTP server
through the control connection:

QUIT <CRLF>

The server should send the command reply 221, and close its socket on the control
connection. Receiving the reply, the client closes its socket on the control connection.

3) Error handling

a. Each child server is responsible for checking the validity and syntax of its
client’s command. Similarly, the FTP client should also check the
validity/syntax of its user commands.

b. On receiving a command from a client, the server should respond


accordingly. For example, if the server receives a RETR command, it should
respond with an error if the requested file is not available, otherwise, the
server sends the requested file. Use the provided reply commands. You may
also see RFC 959 for other relevant reply commands.

c. The server should close the control connection only if the client sends a QUIT
command or if the server does not receive any command (from its client)
within max_wait_time period.

d. Proper handling of mutual exclusion and race conditions is required.

e. You must include all necessary (applicable) conditions discussed in the


textbook (Chapter 5).

Computer Communication 352 2nd Semester 2010

4
Implementation:

1. Your program must be written in ‘C’ using TCP/IPv4 sockets, and must run
on the Department’s machines.

2. The FTP server uses a thread to serve each connecting client. You can create a
new thread or use one available from a pool of threads that you have created
when you started your server.

3. The concurrent FTP server is able to accept up to max_clients simultaneous


connecting clients. The max_clients, and max_wait_time must be arguments
passed to the FTP server when the server is started. The valid numbers for
these arguments are:
• max_clients: 1 to 10.
• max_wait_time: 1 to 120 seconds.

4. If the child server does not receive any command (from its client) within a
max_wait_time, the child server closes its control connection socket and
terminates.

5. The FTP client should be started with either:

client Server_IP_address port


or
client Server_machine_name port

Note, IP_address is the FTP server’s address (in dotted decimal notation).

Once the FTP client is connected to the FTP server, the FTP client waits for
user command, and a prompt “CLIENT>” should be shown on the screen.

OPTIONAL:
For interested students, you may also consider a protocol that requires a user
name and password to use the FTP server. You can use the following reply
commands in your protocol.

220 Service ready for new user.


230 User logged in, proceed.
331 Username OK, password required.

6. Make sure to check for error return from each system call, and to close every
socket created.

7. You MAY make your own assumptions/requirements other than those


already given. However, YOU HAVE TO DOCUMENT ANY ADDITIONAL
ASSUMPTIONS/LIMITATIONS FOR YOUR IMPLEMENTATIONS.

Computer Communication 352 2nd Semester 2010

5
Instruction for submission:

1. Your completed program files server.c and client.c, and all other necessary files and
makefiles must be placed in your home directory, under a directory named:
cc352/assignment/ for marking by the lecturer and graders.

2. You should include:


• A printout of all source code (with acceptable coding standard) for the programs
with proper in-line documentation.
• A text README file describing how to use your program and how it works. Here,
you should include a description for any cases for which your program is known not
working correctly. If you think that your program works perfectly you must describe
how you have tested it.
• A set of sample inputs and outputs from your running programs.

3. Your submitted report must have a cover page, which must include:
• The words “Computer Communications 352 Assignment” or “Computer
Communications 552 Assignment”.
• Your name in the form: family, other names. Your name should be as it is recorded in
the student database.
• Your practical time (example: Wednesday 9-11AM), and your tutor’s name.
• A signed statement that the assignment is your own work.

4. No late assignment submission will be accepted under any circumstances. If your


assignment is incomplete due to illness or other circumstances on or near the submission
date you must submit the partial solution you have completed. Any exceptional
circumstance (assuming that it is supported by a medical certificate or a letter from a
student counsellor) will be taken with consideration by the lecturer and co-examiner in
charge, and/or by the Department’s Board of Examiners.

5. Due dates and other arrangements may only be altered with the consent of the majority of
the students enrolled in the unit and with the consent of the lecturer.

6. Demo requirements:
• You may be required to demonstrate your program and/or sit a quiz during tutorial
sessions (to be announced).
• For demo, you MUST keep the source code for your programs in your home directory,
and the source code MUST be that submitted.
• The programs should run on any machine in the department labs.

Failure to meet these requirements may result in the assignment not being
marked.

Computer Communication 352 2nd Semester 2010

You might also like