實現ftp伺服器的部分功能
1、ls 檢視服務端檔案
2、pwd 檢視服務端所在目錄
3、lls 檢視客戶端檔案
4、lcd *** 進入***目錄
5、get *** 從服務端獲取***檔案到客戶端
6、put *** 從客戶端上傳***檔案到服務端
其中,config_new.**件如下
#define ls 1
#define pwd 2
#define quit 3
#define lls 4
#define lcd 5
#define cd 6
#define get 7
#define put 8
char
*get_file_name
(char
*cmd)
intget_cmd_type
(char
*cmd)
struct msg
;
服務端**如下
#include
#include
#include
/* see notes */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
"config_new.h"
void
cmd_handler
(int iclient_fd,
struct msg server_msg)
;int
cmd_handler_get
(int iclient_fd,
struct msg server_msg)
;int
cmd_handler_put
(int iclient_fd,
struct msg server_msg)
;int
main
(int argc ,
char
**ar**)
iaddrlen =
sizeof
(struct sockaddr)
;bzero
(&server_addr,iaddrlen)
;//³õê¼»¯½á¹¹ìå
server_addr.sin_family = af_inet;
//éèöãµøö·¼ò×å
server_addr.sin_port =
htons
(8013);
//éèöã¶ë¿ú
server_addr.sin_addr.s_addr =
inet_addr
("127.0.0.1");
//éèöãµøö·if(
-1==bind
(iserver_fd,
(struct sockaddr *
)&server_addr,iaddrlen)
)/* bindµä걺ò½øððת»¯ */if(
-1==listen
(iserver_fd,10)
)printf
("connecting ...\n");
int n_recv;
pid_t uipid;
while(1
) uipid =
fork()
;if(uipid ==0)
if(n_recv ==0)
else
if(n_recv >0)
}}}close
(iserver_fd)
;return0;
}void
cmd_handler
(int iclient_fd,
struct msg server_msg)
//switch end
}int
cmd_handler_put
(int iclient_fd,
struct msg server_msg)
else
if(server_msg.flag ==1)
write
(file_fd,server_msg.file_data,
strlen
(server_msg.file_data)-2
);memset
(&server_msg,0,
sizeof
(server_msg));
}close
(file_fd)
;return0;
}}intcmd_handler_get
(int iclient_fd,
struct msg server_msg)
else
else
send
(iclient_fd,
&server_msg,
sizeof
(server_msg),0
);memset
(&server_msg,0,
sizeof
(server_msg));
}close
(file_fd)
;return0;
}}}
客戶端**如下
#include
#include
/* see notes */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
"config_new.h"
intcmd_handler
(int iclient_fd,
struct msg client_msg)
;int
cmd_handler_get
(int iclient_fd,
struct msg client_msg)
;int
cmd_handler_put
(int iclient_fd,
struct msg client_msg)
;int
main()
iaddrlen =
sizeof
(struct sockaddr)
;bzero
(&iclientaddr,iaddrlen)
;//3?¨º??¡¥?¨¢11¨¬?
iclientaddr.sin_family = af_inet;
//¨¦¨¨??¦ì??¡¤?¨°¡á?
iclientaddr.sin_port =
htons
(8013);
//¨¦¨¨?????¨²
iclientaddr.sin_addr.s_addr =
inet_addr
("127.0.0.1");
//¨¦¨¨??¦ì??¡¤
int iconnect =
connect
(iclient_fd,
(struct sockaddr*
)&iclientaddr,iaddrlen);if
(iconnect ==-1
)else
while(1
)if(send
(iclient_fd,
&client_msg,
sizeof
(client_msg),0
)==-1
)cmd_handler
(iclient_fd,client_msg);}
close
(iclient_fd)
;return0;
}int
cmd_handler
(int iclient_fd,
struct msg client_msg)
//switch end
return0;
}int
cmd_handler_put
(int iclient_fd,
struct msg client_msg)
else
else
send
(iclient_fd,
&client_msg,
sizeof
(client_msg),0
);memset
(&client_msg,0,
sizeof
(client_msg));
}close
(file_fd)
;return0;
}}}int
cmd_handler_get
(int iclient_fd,
struct msg client_msg)
else
if(client_msg.flag ==1)
write
(file_fd,client_msg.file_data,
strlen
(client_msg.file_data)-2
);memset
(&client_msg,0,
sizeof
(client_msg));
}close
(file_fd)
;return0;
}}
伺服器實現 FTP伺服器的實現(C語言)
我們在之前的文章中,曾經對ftp檔案傳輸協議做過詳細的介紹。本章,我們對如何用c語言實現ftp伺服器做乙個簡單的介紹。概述 ftp檔案傳輸協議,是網際網路上使用得最廣泛的檔案傳輸協議。ftp提供互動式的訪問,允許客戶指明檔案的格式與型別,並允許檔案具有儲存許可權。ftp遮蔽了不同作業系統之前的細節,...
C 上傳FTP伺服器
using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...
依賴型別語言Idris發布1 0版本
英國聖安德魯大學講師 idris建立者edwin brady寫道,在達到alpha階段幾個月之後,idris 1.0發布。u0026 xd u0026 xd 1.0版本發布,最關鍵的一點是其核心語言及基礎庫都被認為是穩定的,就是說,將來的1.x版本應該確保源 向後相容。自alpha版本以來,idri...