Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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;

public:
	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();
	CFTPServer();
	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, ...);

private:
	// 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
public:
	BOOL CheckMaxUsers();
	void Initialize(CFTPEventSink *pEventSink);

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CFTPServer)
	//}}AFX_VIRTUAL

// Generated message map functions
protected:
	int m_nSecurityMode;
	int m_nStatisticsInterval;
	//{{AFX_MSG(CFTPServer)
	afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG
	LRESULT OnThreadClose(WPARAM wParam, LPARAM lParam);
	LRESULT OnThreadStart(WPARAM wParam, LPARAM);
	LRESULT OnThreadMessage(WPARAM wParam, LPARAM lParam);
    DECLARE_MESSAGE_MAP()
};

#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.

License

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

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