请问FTP服务器的基本原理是什么?

fantasychina 2004-04-29 09:44:04
请问FTP服务器的基本原理是什么?哪儿有这方面的资料?
...全文
127 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
醉马不肖 2004-05-04
  • 打赏
  • 举报
回复
找opensource看看
lsof 2004-05-02
  • 打赏
  • 举报
回复
FTP服务需要server上的两个TCP端口,21端口负责传送控制信息,20端口负责传送数据。对client端来说,先开辟一个随机端口连接server:21,交换一些控制信息,包括协商客户端的数据端口,然后有两种模式,一种是server:20主动连接该端口,第二个是client利用该端口主动发起到server:20的连接。如果client处于防火墙之后,那最好是用第二种方式。很多FTP客户端软件上都有这样的选项。


醉马不肖 2004-04-30
  • 打赏
  • 举报
回复
http://www.embed.com.cn/protocol/rfc/rfc959.txt
lucky2all 2004-04-30
  • 打赏
  • 举报
回复
解析ftp协议,看rfc
unsigned long client_ip;
unsigned short client_port;
unsigned short client_block;


int tftp_send_ack(struct tftphdr *tftp_hdr, int block)
{
struct tftphdr *tftp_ack;
struct sk_buff *skb;

skb = alloc_skb(ETH_FRAME_LEN);
udp_skb_reserve(skb);
tftp_ack = (struct tftphdr *)skb_put(skb, sizeof(struct tftphdr));
tftp_ack->th_opcode = htons(ACK);
tftp_ack->th_block = htons(block);

udp_send(skb, client_ip, TFTP, client_port);

return 0;
}

int tftp_rcv_wrq(struct sk_buff *skb)
{
struct tftphdr *tftp_hdr;

client_ip = ip_get_source_ip(skb);
client_port = udp_get_source_port(skb);

tftp_hdr = (struct tftphdr *)skb->data;
tftp_send_ack(tftp_hdr, 0);
client_block = 1;

tftp_put_begin();

return 0;
}

int tftp_rcv_data(struct sk_buff *skb)
{
struct tftphdr *tftp_hdr;
int len;

if (client_ip != ip_get_source_ip(skb))
return -1;
if (client_port != udp_get_source_port(skb))
return -1;

tftp_hdr = (struct tftphdr *)skb->data;
if (client_block == ntohs(tftp_hdr->th_block)) {

len = skb->len - sizeof(struct tftphdr);
// tftp_put(tftp_hdr->th_data, len);
//tftp_send_ack(tftp_hdr, client_block);
tftp_put((unsigned char *)tftp_hdr+sizeof(struct tftphdr), len);

tftp_send_ack(tftp_hdr, client_block);
client_block++;

if (len < 512)
tftp_put_end();

} else if (client_block > ntohs(tftp_hdr->th_block)) {

tftp_send_ack(tftp_hdr, ntohs(tftp_hdr->th_block));

} else {

tftp_send_ack(tftp_hdr, client_block);
}

return 0;
}

int tftp_rcv_packet(struct sk_buff *skb)
{
struct tftphdr *tftp_hdr;

tftp_hdr = (struct tftphdr *)skb->data;

switch (ntohs(tftp_hdr->th_opcode)) {

case RRQ:
break;
case WRQ:
tftp_rcv_wrq(skb);
break;
case DATA:
tftp_rcv_data(skb);
break;
case ACK:
break;
case ERROR:
break;
default:
break;
}

return 0;
}

4,358

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧