Professional Documents
Culture Documents
4522)
Assignment
Objective:
Requirement:
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.
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.
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:
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.
Following RFC 959, the FTP client sends the following command to the FTP server
via the control connection:
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:
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:
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.
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.
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.
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.
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.
6. Make sure to check for error return from each system call, and to close every
socket created.
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.
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.
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.