FTP 服务器与客户端设计与开发详细设计程序包括 5 个主要功能::启动和停止 FTP :添加用户,:设置服务器开放端口,::允许连接服务器的 IP 列表,以及禁止访问的 IP服务器的运行模块功能:负责 FTP 服务器的运行。使用类:CFTPServer 类,CApplicationDlg 类,CListenSocket onnectThread onnectSocket 类各种类的功能: 类:是 CWnd 的子类,作为程序的顶层类, 类:CDialog 类的子类,实现程序主窗口。 类:负责监听 FTP 客户端连接,onnectThread 类:负责实现并保证多个连接的有效性。onnectSocket 类:实现 FTP 命令的解析,数据的发送和接收CFTPServer 类作为服务器的顶层类,实现服务器开始运行时的所有成员函数申明如下:class CFTPServer : public CWnd{onnectSocket;//CConnectSocket 作为其友元类,可以访问内部私有数据成员public:void SetGoodbyeMessage(LPCTSTR lpszText);//发送退出信息void eMessage(LPCTSTR lpszText);//发送欢迎信息void SetTimeout(int nValue);//设置暂停时间void SetPort(int nValue);//设置端口void SetMaxUsers(int nValue);//设置最大连接数void SetStatisticsInterval(int nValue);//统计时间间隔BOOL IsActive();//是否有效void Stop();BOOL Start();CFTPServer();virtual ~CFTPServer();CUserManager m_UserManager;//用户管理对象CSecurityManager m_SecurityManager;//安全策略CFTPServer 类最主要的成员函数是 start()和 stop(),分别负责 ftp 服务器的开始运行和结束运行函数声明如下:/********************************************************************//* *//* Function name : Start *//* Description : Start listining on port 21 and accept new *//* connections. *//* *//********************************************************************/BOOL CFTPServer::Start(){if (m_bRunning)return FALSE;//如果运行,返回错误标志// create dummy window for message routingif (!CWnd::CreateEx(0, AfxRegisterWndClass(0), "FTP Server NotificationSink", WS_POPUP, 0,0,0,0, NULL, 0)){AddTraceLine(0, "Failed to create notification window.");return FALSE;}// 开始创建 socketif ((m_nPort)){// start listeningif (()){ = this;m_bRunning = TRUE;SetTimer(1, m_nStatisticsInterval, NULL);AddTraceLine(0, "FTP Server started on port %d.", m_nPort);return TRUE;}}AddTraceLine(0, "FTP Server failed to listen on port %d.", m_nPort);// destroy notification windowif (IsWindow(m_hWnd))DestroyWindow();m_hW
FTP服务器与客户端设计与开发 来自淘豆网m.daumloan.com转载请标明出处.