dasima / ftpserver Goto Github PK
View Code? Open in Web Editor NEWmini版FTP服务器实现文件上传和下载、断点续传、限速等功能
mini版FTP服务器实现文件上传和下载、断点续传、限速等功能
既然在进行数据传输相关操作时,proto进程总是需要向nobody去申请一个可用的数据管道,那为什么不让nobody作为一个独立的多线程对数据管道做管理呢?
不然每接受一个accept,都要创建两个进程实在有点浪费资源。。而且nobody并没有起到数据传输的作用,事实上的数据传输还是proto进程做的。。
//获取监听fd
void privop_pasv_listen(Session_t *sess)
{
//创建listen fd
char ip[16] = {0};
get_local_ip(ip);
/* 打开的端口号是固定的 20 号 */
int listenfd = tcp_server(ip, 20);
sess->listen_fd = listenfd;
我看 FRC 中提到的是服务器端随机打开一个端口并监听的,而且之前服务器防火墙一直打开20号端口,然后 "LIST" 连接服务器的时候一直没能获取到文件列表;我之前用的 pure-ftpd 是指定一段端口,用于 PASV 模式监听的。
ftpServer/priv_command.c
文件中的 函数,不太看的懂其实现的功能//获取数据套接字
void privop_pasv_get_data_sock(Session_t *sess)
{
char ip[16] = {0};
priv_sock_recv_str(sess->nobody_fd, ip, sizeof ip);
uint16_t port = priv_sock_recv_int(sess->nobody_fd);
//创建fd
/* 这里直接指定 20 号端口是用于什么的呢? */
int data_fd = tcp_client(20);
struct sockaddr_in addr;
memset(&addr, 0, sizeof addr);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(ip);
addr.sin_port = htons(port);
int ret = connect_timeout(data_fd, &addr, tunable_connect_timeout);
if(ret == -1)
ERR_EXIT("connect_timeout");
priv_sock_send_result(sess->nobody_fd, PRIV_SOCK_RESULT_OK);
priv_sock_send_fd(sess->nobody_fd, data_fd);
close(data_fd);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.