Click here to Skip to main content
12,897,945 members (86,336 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.
/*																*/
/*  LISTSOCKET.CPP												*/
/*																*/
/*  Implementation of the Listen Socket.						*/
/*  The server listens for connections. When a new connection	*/
/*  is requested, the server accepts the connection and then	*/
/*  creates a connect thread to handle the connection.			*/
/*																*/
/*  Programmed by Pablo van der Meer							*/
/*  Copyright Pablo Software Solutions 2005						*/
/*						*/
/*																*/
/*  Last updated: May 28, 2005									*/
/*																*/

#include "stdafx.h"
#include "FTPServerApp.h"	
#include "FTPServer.h"	
#include "ApplicationDlg.h"
#include "ListenSocket.h"
#include "ConnectThread.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;

	m_pWndServer = NULL;


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CListenSocket, CAsyncSocket)
#endif	// 0

/*																	*/
/* Function name : OnAccept											*/		
/* Description   : Called by the framework to notify this listening	*/
/*				   socket that it can accept pending connection		*/
/*				   requests by calling the Accept member function.	*/
/*																	*/
void CListenSocket::OnAccept(int nErrorCode) 
	// New connection is being established
	CSocket sockit;

	// Accept the connection using a temp CSocket object.

	// Create a thread to handle the connection. The thread is created suspended so that we can
	// set variables in CConnectThread before it starts executing.
	CConnectThread* pThread = (CConnectThread*)AfxBeginThread(RUNTIME_CLASS(CConnectThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
	if (!pThread)
		TRACE("Could not create thread\n");

	CFTPServer *pWnd = (CFTPServer *)m_pWndServer;

    // since everything is successful, add the thread to our list

	// save pointer
	pThread->m_pWndServer = m_pWndServer;

	// Pass the socket to the thread by passing the socket handle. You cannot pass
	// a CSocket object across threads.
	pThread->m_hSocket = sockit.Detach();

	// Now start the thread.


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.170424.1 | Last Updated 30 May 2005
Article Copyright 2002 by Pablo van der Meer
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid