Project report
Design and
implementation of
FTP Client
Course Title: Internet Application
Name:
王可惟
梁扬
Date:
2013 年 6 月 13 日
1. Overview
This project aims to build an FTP client program, operating under linux CMD window.
This program allows basic file operation, including making directory, renaming and
deleting files, and provides upload/download functions. You can enter “help” to check
how to use related commands.
2. Requirements Analysis
To realize a perfect ftp client, we define our development environment and details
functional requirements.
2.1) Basic functions:
The FTP server port number is 21. During the runtime you don't have to enter the
port number. The address can be the domain name or IP address. FTP client can
operate modes such as: / FTPCLT openware.byr.edu.cn or/FTPCLT 211.68.71.80.
FTP client connect FTP server over TCP protocol. FTP can receive response from
the server. It can also convert user input command to the FTP command and sent
to the server.
Support the user's login authentication, can hide the password.
Support Passive mode (Passive mode).
FTP client supports the following commands:
The PWD, ls, CDS, put, get, quit, mkdir, delete and rename, etc.
Support the simple statistical functions: such as the transmission speed, traffic;
Write complete design documentation (reference Sample - Project - Report. PDF).
The program should include detailed code comments with good programming
style.
The program runs steady, supports error handling, such as: the command is invalid,
loss of parameter, processing with files with same name, blank characters.
2.2) Extended functions:
Can upload and download within limits for given speed;
Support Binary mode;
Friendly interface: highlighting different types of documents;
Support the breakpoint, etc.
3. PreliminaryDesign
3.1) Decomposition of functional modules
We divide the program in several function modules. The five major modules(functions)
are:
main();
cmd_tcp();
ftp_list();
ftp_get();
ftp_put();
The following modules(functions) are been called by these five major modules:
cliopen();
strtosrv();
3.2) Relationship and interface between each modules
The definition and use of each function:
int cliopen(char *host, char *port)
Used for set up a TCP connection if host
and port are known
void strtosrv(char *str, char *host, char
*port)
Used for processing the reply code from
server(Code 227:
(xxx.xxx.xxx.xxx.xxx.xxx)) to get the
provided host address and port.
void cmd_tcp(int sockfd)
Used for processing the command of the
client and the reply code from server
void ftp_list(int sockfd)
Function to deal with “ls” command
int
ftp_get(int sck, char
*pDownloadFileName_s)
Function to deal with “get” command
int
ftp_put (int ds, char
*pUploadFileName_s)
Function to deal with “put” command
The calling relationships between these modules are shown as follows:
Main(): Cliopen() Cmd_tcp()
Cmd_tcp(): Cliopen() Strtosrv() ftp_list() ftp_put() ftp_get()
ftp_get(): Printsize()
ftp_put(): Printsize()
3.3) Overall flowchart
4. Detailed Design
4.1) Input table
Input:
Description of function:
pwd
Display the current directory in server.
cd
Open a particular directory on the server.
ls
Display the file list in the current directory.
Can highlight different kinds of files.
put
Upload file to server.
Can show flow and average speed.
Support resuming of transferring.
get
Download file from server.
Can show flow and average speed.
Support resuming of transferring.
quit
Quit from server.
mkdir
Make a new directory with the name given by user.
delete
Delete a file.
remove
Remove a blank directory.
rename
Rename a file or a directory.
limit
Limit the upload speed to N kB/s. N is given by user.
re-get
Using resuming to download a file from breakpoint.
re-put
Using resuming to upload a file from breakpoint.
Ascii/binary
Switch binary mode to ASCII mode. Or switch ASCII mode to
binary mode.
4.2) ftp_get(int sck, char *pDownloadFileName_s):
Functionality: This module is used to download file from the FTP server.
Description:
(1) First check flag to select get or re-get
(2) First, It the downloading file hasn’t been downloaded before, we set the offset to the
start of the file. Otherwise, we set the offset to the last breakpoint, returned by
ftell(p).
(3) Then, we set the clock to record when we started downloading, and print the name
and size of the file.
(4) Next, we will enter the downloading loop. Following function will be performed
until we finish downloading: