Homework 2
The homework is due Friday, February 11th at 11:59pm. All
assignments are to be carried out individually. No collaboration is
allowed.
The Assignment
In this assignment, you will implement a swarming FTP client
application using the socket API. The application is called mftp,
and must be implemented in C. The FTP protocol is specified in
RFC 959.
The assignment can be broken down into two components: basic ftp
operation and swarming downloads. Both components must be
completed by the due date.
Basic Operation
The client application will take an FTP server and a file
name as command-line parameters. When executed, the client
will simply retrieve the file specified using the FTP
protocol and save it to a local file with the same name. Note: you will not need to implement the put operation.
For example, by executing:
% mftp -s ftp.ucsb.edu -f /robots.txt
The file named robot.txt will be created in the
current directory.
On success, the mftp application exits with code
0. If an error occurs, the application exits with
the the appropriate code and prints a human-readable error
message on standard error.
Other command line options include:
-
-h or --help
-
Prints a synopsis of the application usage and exits with
return code 0.
-
-v or --version
-
Prints the name of the application, the version number
(in this case the version has to be 0.1), the
author, and exits, returning 0.
-
[-f file] or [--file
file]
-
Specifies the file to download.
-
[-s hostname] or [--server
hostname]
-
Specifies the server to download the file from.
-
[-p port] or [--port
port]
-
Specifies the port to be used when contacting the server.
(default value: 21).
-
[-n user] or [--username
user]
-
Uses the username user when logging into the FTP
server (default value: anonymous).
-
[-P password] or [--password
password]
-
Uses the password password when logging into the
FTP server (default value:
user@localhost.localnet).
-
-a or --active
-
Forces active behavior (the server opens the data
connection to the client) (default behavior: passive
behavior).
-
[-m mode] or [--mode
mode]
-
Specifies the mode to be used for the transfer (ASCII or
binary) (default value: binary).
-
[-l logfile] or [--log
logfile]
-
Logs all the FTP commands exchanged with the server and the
corresponding replies to file logfile. If the filename is
"-" then the commands are printed to the standard
output. The lines must be prepended by C->S: or
S->C: for client-to-server and server-to-client lines,
respectively. For example:
S->C: 220 ProFTPD 1.2.10 Server (UCSB) [128.111.24.43]
C->S: USER anonymous
S->C: 331 Anonymous login ok, send your complete email address as your password.
C->S: PASS user@localhost.localnet
Multi-server Swarming
The next part of the assignment is to implement a "swarming" version of ftp download. The idea is that the
mftp
client uses separate threads to simultaneously connect to multiple
servers, and download the same file from different positions in the
same file. On the server side, this functionality is already
supported by current ftp servers through the "restart marker" option.
There's no intuitive user interface for this type of functionality. So
we will use something very simple and straightforward.
mftp takes in an additional commandline argument:
[-w swarm-config-file] or [--swarm swarm-config-file]
Specifies the login, password, hostname and absolute path to the file
When mftp reads in the swamp-config file, it parses the N servers on
the list. For each of the N servers, mftp spawns a separate
thread, connects to the server, and moves to the specified directory.
To download a file of S bytes, mftp performs a swaming download,
where each thread downloads a segment of S/N bytes. The downloaded
segments should be put together to form the entire file.
Note: mftp can use the --swarm option simultaneously with
the -l option.
The format should be:
ftp://username:password@servername/file-path.
An example of the swarm-configuration file is as follows:
ftp://socket:programming@192.168.0.2/cook.pdf
ftp://176b:176b@192.168.0.5/cook.pdf
ftp://socket:programming@192.168.0.2/cook.pdf
ftp://176b:176b@192.168.0.5/pub/cook.pdf
Discussion
This application must be extremely resilient to
wrong/unexpected input data, repeated values, etc. Part of
your assignment is to understand how the mftp application could be abused by a user and to provide
meaningful error messages if something goes wrong. You have
to program defensively and with user-friendliness in mind.
Segmentation fault is not an option!
You CANNOT use any existing library to retrieve the files
from the server. You have to write your own code that will
open connections, play the protocol, parse the data
received from the server, etc.
The application should return meaningful error messages if
an error occurs. In addition, the exit value should give
some information about what happened. By returning
different exit values in association with different errors
the application becomes easily scriptable (that is, an
external script can invoke the application and manage error
conditions).
Obviously it is impossible to foresee all possible error
conditions, therefore the following list is obviously
incomplete.
Exit code
|
Explanation
|
0
|
Operation successfully completed
|
1
|
Can't connect to server
|
2
|
Authentication failed
|
3
|
File not found
|
4
|
Syntax error in client request
|
5
|
Command not implemented by server
|
6
|
Operation not allowed by server
|
7
|
Generic error
|
Miscellaneous notes
-
Note that when invoked without any parameters the
application should behave as if it were invoked with the
--help option.
-
All error message must be printed to standard error.
-
If a parameter is specified multiple times, then the last
value assigned to the parameter is the value accepted.
Submission
The submission process for this assignment uses the turnin
package. Do a man turnin to find more info about
this program. The name of the assignment is mftp.
Your submission must contain one source file called mftp.c that contains all code for your
application. In addition, you have to write a brief
README file that describes your application (and
possible issues and problems). You also have to include a
file called AUTHORS that contains your name and
your email address. Finally, you need to include a
Makefile file that describes how to build your
application.
To submit:
- Create a directory whose name is your CS account. For
example, user John Doe --whose account is jdoe--
would do:
% mkdir jdoe
- Put in the directory all files for homework 2.
- Execute the turnin program. For
example, user jdoe would execute:
% turnin mftp@cs176b jdoe
You can execute turnin up to 10 times
per project. Earlier versions will be discarded. The timestamp of turnin
has to be before the due date.