Click here to Skip to main content
12,820,894 members (31,496 online)
Click here to Skip to main content


164 bookmarked
Posted 11 Jul 2002

A Complete FTP Server

, 30 May 2005
This article presents a fully functional implementation of a FTP server.
// FTPServer.h: interface for the CFTPServer class.

#if !defined(AFX_FTPSERVER_H__144E8B64_2004_4709_B55A_242FE5F07BD2__INCLUDED_)
#define AFX_FTPSERVER_H__144E8B64_2004_4709_B55A_242FE5F07BD2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ConnectThread.h"
#include "ListenSocket.h"
#include "FTPEventSink.h"
#include "UserManager.h"

class CFTPServer : public CWnd
	friend CControlSocket;

	void SetGoodbyeMessage(LPCTSTR lpszText);
	void SetWelcomeMessage(LPCTSTR lpszText);
	void SetTimeout(int nValue);
	void SetPort(int nValue);
	void SetMaxUsers(int nValue);
	void SetStatisticsInterval(int nValue);
	BOOL IsActive();
	void Stop();
	BOOL Start();
	virtual ~CFTPServer();

	CUserManager m_UserManager;

	CCriticalSection m_CriticalSection;

    // list of thread pointers
    CTypedPtrList<CObList, CConnectThread*> m_ThreadList;

	int GetPort() { return m_nPort;	};
	int GetMaxUsers() {	return m_nMaxUsers;	}
	int GetTimeout() { return m_nTimeout; }
	int GetConnectionCount() { return m_nConnectionCount; }
	CString GetWelcomeMessage() { return m_strWelcomeMessage; };
	CString GetGoodbyeMessage() { return m_strGoodbyeMessage; };
	void AddTraceLine(int nType, LPCTSTR pstrFormat, ...);

	// socket member that listens for new connections
	CListenSocket m_ListenSocket;
	CFTPEventSink *m_pEventSink;

	int		m_nPort;
	int		m_nMaxUsers;
	CString	m_strWelcomeMessage;
	CString	m_strGoodbyeMessage;
	int		m_nTimeout;
	BOOL	m_bRunning;

	// statistics
	DWORD m_dwTotalReceivedBytes;
	DWORD m_dwTotalSentBytes;
	int	m_nConnectionCount;
	int m_nTotalConnections;
	int m_nFilesDownloaded;
	int m_nFilesUploaded;
	int m_nFailedDownloads;
	int m_nFailedUploads;

	// Operations
	BOOL CheckMaxUsers();
	void Initialize(CFTPEventSink *pEventSink);

// Overrides
    // ClassWizard generated virtual function overrides

// Generated message map functions
	int m_nSecurityMode;
	int m_nStatisticsInterval;
	afx_msg void OnTimer(UINT nIDEvent);
	LRESULT OnThreadClose(WPARAM wParam, LPARAM lParam);
	LRESULT OnThreadStart(WPARAM wParam, LPARAM);
	LRESULT OnThreadMessage(WPARAM wParam, LPARAM lParam);

#endif // !defined(AFX_FTPSERVER_H__144E8B64_2004_4709_B55A_242FE5F07BD2__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Pablo van der Meer
Web Developer
Netherlands Netherlands
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 30 May 2005
Article Copyright 2002 by Pablo van der Meer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid