程序代写代做代考 FTP compiler Final Project – FTP Proxy

Final Project – FTP Proxy
BUPT/QMUL 5/11/2016

Mission (1/4)
• Based on the provided framework, design and implement a FTP Proxy
programme that …
–Implement all required functions indicated in Guide Document.
–Use Linux C language and Ubuntu Server 12.04 (or higher version) as developing environment.
–Use gcc as compiler
–Use CLI (Command Line Interface) as input & output
–MUST NOT “#include” any existing library or project (except the standard library)
2

Mission (2/4)
• You need to ……
– Implement the programme and upload the source code (with comments version) to FTP server.
– Based on the template, write a technical report and upload it to FTP server.
Server: ftp://niclab.bupt.edu.cn,port:21
User name: gjxy2016 password: student
Use campus network to upload or you cannot login correctly
– Two persons as a group (Loner is accepted but three persons or more WILL NOT be accepted). One
programme and one report are needed for each group.
– Deadline: before 17:00, 2016-06-17 (UTC+8)
– Please contact yarchmage@outlook.com if the FTP server crashed……
3

Mission (3/4)
• About the framework and your programme
– It is just a reference that provide basic logic. You can easily “fill in” the blank and implement the functions or design your own architecture.
– Code comment is needed in your upload version.
• About the report
– Refer to the template and write your technical report
– A module description of your programme is necessary.
– Basic logic description, the architecture, function description and so on.
• About the check
– Live demonstration.
– Source code Q&A WITHOUT code comment. [Please delete all comments before checking.] – At least 3 questions will be asked for each person.
– Carry your 学生证 (with 照片)
4

Mission (4/4)
• Detail of your uploading
– Please save your report as PDF version. Name it with your BUPT-IDs.
– Please encapsulate all your .c files, .h files, .pdf report and .txt file in a ZIP or RAR file. Then name it with your BUPT-IDs, such as 2010919240_2010919241_ver1.zip
– BE CAREFUL. It is a write only folder so that increase your ver value and re-upload when encounter error.
5

What is Proxy?
6

What is Proxy?
Windows/Mac
Ubuntu
FileZilla/MacOS Server
FileZilla Client
192.168.56.1
Proxy
192.168.56.101
Host-Only Netwrok
login 192.168.56.101:21
7

Description of 6 sockets (Active mode, Download)
proxy_cmd_socket connect_cmd_socket
13
accept_cmd_socket proxy_data_socket
24
connect_data_socket
Client 6
Proxy
accept_data_socket
5 Server
• proxy_cmd_socket: listen控制连接
• accept_cmd_socket: accept客户端请求的控制连接
• connect_cmd_socket: connect服务器建立控制连接
• proxy_data_socket: listen数据连接
• accept_data_socket: accept得到请求的数据连接(主动模式时accept得到服务器数据连接的请求,被动 模式时accept得到客户端数据连接的请求)
• connect_data_socket: connect建立数据连接 (主动模式时connect客户端建立数据连接,被动模式时 connect服务器端建立数据连接)
8

select() – the most important function
int select ( int maxfdp, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval*timeout );
struct fd_set:可以理解为一个集合,这个集合中存放的是文件描述符。程序执行select函数后会这里等
待,直到被监视的文件描述符集合中有一个或多个发生了状态改变。
Parameters:
int maxFdp:集合中所有文件描述符的范围,即所有文件描述符的最大值加1 fd_set *readfds: 监视结合中文件描述符的读变化
fd_set *writefds:监视结合中文件描述符的写变化
fd_set *errorfds:监视文件错误异常
struct timeval*timeout: 设置超时时间
Return:
int: 负值:select出现错误。
0: 等待超时,根据struct timeval*timeout判断是否超时。 正值:当发生读变化、写变化、错误异常等操作
9

select() example
int fd, next=0; /* original socket */ int newfd[10]; /* new socket descriptors */ while(1) {
fd_set readfds;
FD_ZERO(&readfds); FD_SET(fd, &readfds);
/* Now use FD_SET to initialize other newfd’s that have already been returned by accept() */
select(maxfd+1, &readfds, 0, 0, 0); if(FD_ISSET(fd, &readfds)) {
newfd[next++] = accept(fd, …);
}
/* do the following for each descriptor newfd[n] */ if(FD_ISSET(newfd[n], &readfds)) {
}
Now the server can support multiple connections…
}
read(newfd[n], buf, sizeof(buf)); /* process data */

Module description (Active mode, download)
Begin
proxy_socke t (bind, listen)
select()
Create : accept_data_socket connect_data_socket
proxy_data_socket
Close: accept_data_socket connect_data_socket
accept_data_socket
write to connect_data_socket
Fault
connect_data_socket
proxy_cmd_socket
YES
NO
recv == 0 ?
Listen and Judge CMD
Listen and Judge REPLY
End
11
Create : accept_cmd_socket connect_cmd_socket
accept_cmd_socket
Process CMD
write to connect_cmd_socket
connect_cmd_socket
Process REPLY
write to accept_cmd_socket

Hints
• There are something different between active mode and passive mode (connect_data_socket and accept_data_socket)
• Please improve the module chart and write it in your report – Think about active mode and passive mode
– Think about download and upload
12

Client Installation
• FileZilla Client is suggested as FTP client
– Download from https://filezilla-project.org/
– For Windows: Next -> Next -> Yes -> Yes -> …… ->
– For MacOS: Drag the .app into Application ->
13

Switch Active and Passive Mode
14