资源简介
以前写来练手的linux下的ftp服务器,C语言实现的,支持PORT和PASV模式,主要还是支持下载及部分ftp标准指令。可编译和可运行,代码比较简单和清晰,可帮助理解ftp协议。
如果去看
代码片段和文件信息
//homework ftp server
//wgt 2011-2-27 modified at 8-27
#include “ftp.h“
#include
int delspace(char *str)
{
char *p = str;
if (str == NULL)
return -1;
while( *p == ‘ ‘)
++p;
strcpy(str p);
return 0;
}
//return value: length of cmd string
int getcmdstr(const char *src char *dest int destlen)
{
const char *p = NULL;
int i = 0;
if (src == NULL || dest == NULL)
return -1;
p = src;
while((*p != ‘ ‘) && (*p != ‘\r‘) && (*p != ‘\0‘) && (i < (destlen -1)) ) //
dest[i++] = *p++;
dest[i] = ‘\0‘;
return i;
}
int cmdparse(char *src int *cmdlen)
{
int len = -1;
char *p = NULL;
char cmdstr[BUF_LEN] = {0}; //cmdstr[] is ONLY command WITHOUT argument
if (src == NULL || cmdlen == NULL)
return -1;
// delspace(src); //delete lead space char and command argument
*cmdlen = getcmdstr(src cmdstr BUF_LEN);
if(-1 == *cmdlen)
return -1;
len = strlen(src);
p = src;
if (strcmp(cmdstr “AUTH“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return AUTH;
}else if ( strcmp(cmdstr “USER“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return USER;
}else if (strcmp(cmdstr “PASS“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return PASS;
}else if (strcmp(cmdstr “SYST“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return SYST;
}else if (strcmp(cmdstr “FEAT“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return FEAT;
}else if (strcmp(cmdstr “TYPE“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return MODE;
}else if (strcmp(cmdstr “SIZE“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return SIZE;
}else if (strcmp(cmdstr “REST“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return REST;
}else if (strcmp(cmdstr “PASV“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return PASV;
}else if (strcmp(cmdstr “LIST“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return LIST;
}else if (strcmp(cmdstr “NLST“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return NLST;
}else if( strcmp(cmdstr “STOR“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return STOR;
}else if( strcmp(cmdstr “CWD“) == 0
&& strcmp(p+len -2 “\r\n“) == 0 ){
return CWD;
}else if( strcmp(cmdstr “DELE“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return DELE;
}else if( strcmp(cmdstr “PORT“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return PORT;
}else if( strcmp(cmdstr “RETR“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return RETR;
}else if( strcmp(cmdstr “PWD“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return PWD;
}else if (strcmp(cmdstr “XPWD“) == 0
&& strcmp(p+len -2 “\r\n“) == 0){
return XPWD;
}else if( strcmp(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-06-08 14:05 my_ftpserver_good\
文件 3915 2011-08-28 13:14 my_ftpserver_good\cmd.txt
文件 3127 2013-06-08 16:52 my_ftpserver_good\cmdparse.c
文件 1771 2013-06-08 16:52 my_ftpserver_good\ftp.h
文件 716 2011-08-26 16:06 my_ftpserver_good\Makefile
文件 27719 2013-06-08 16:49 my_ftpserver_good\server.c
评论
共有 条评论