Edit: bonjour au lecteur de passage; Avant que vous ne lisiez cet article et n'utilisiez cette librairie, je voudrais vous informer que ce code a été écrit durant ma période de formation au C++ et ne correspond pas à mes critères actuels de qualités. Je vous déconseillerai donc d'utiliser ce code dans quelque projet critique que ce soit. Néanmoins, dans la mesure où ce code pourrait permettre de mieux appréhender le protocole FTP, j'ai pris la décision de ne pas effacer cet article.
CFtpServer est une Class C++ qui permet aux developpers d' inserer dans leurs programmes un server FTP rapide, simple, et fonctionnel. CFtpServer est multithreadé et tourne en parallele de votre code.
Commandes supportées :
USER, PASS, SITE, SITE EXEC, HELP, REIN, SYST, STRU, MODE, TYPE, PORT, PASV, LIST, NLST, CWD, XCWD, FEAT, MDTM, PWD, XPWD, CDUP, XCUP, STAT, ABOR, REST, RETR, STOR, APPE, STOU, SIZE, DELE, RNFR, RNTO, MKD, XMKD, RMD, XRMD
Compile sans pb avec VC++6, Dev-C++, gcc WIN32/LINUX
Votez SVP !
http://sourceforge.net/projects/cftpserver/
theBrowser
Source / Exemple :
/*
- CFtpServer :: a FTP Server Class Library
- Copyright (C) 2005, Poumailloux Julien aka theBrowser
*
- Mail :: thebrowser@gmail.com
Copyright (c) 2005 POUMAILLOUX Julien
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
g++ ./CFtpServer/CFtpServer.cpp ./Example/main.cpp -o FtpServer -lnsl -lpthread
Under SunOS and mayber some other OS, you may need to link to '-lsocket' too.
#include "../CFtpServer/CFtpServer.h"
int main( int argc, char * argv[] )
{
#ifdef WIN32
WSADATA WSAData;
if( WSAStartup( MAKEWORD(2, 0), &WSAData) != 0 ) {
printf("-WSAStartup failure: WSAGetLastError=%d\r\n", WSAGetLastError() );
return 0;
}
#endif
CFtpServer FtpServer;
FtpServer.SetPort(21); // default FTP port is 21
FtpServer.SetDataPortRange( 100,100 ); // data TCP-Port range = [100-199]
#ifdef CFTPSERVER_ANTIBRUTEFORCING // See CFtpServer.h, not defined by default
FtpServer.SetCheckPassDelay( 1500 ); // kind of bruteforcing protection
#endif
if( FtpServer.AllowAnonymous( true, "C:/anonymous" ) == false ) { // allow anonymous user
printf("-Unable to create anonymous user; Make sure its StartPath exists!(C:/anonymous)\r\n");
}
#ifdef WIN32
CFtpServer::UserNode *FtpUser = FtpServer.AddUser( "test", "pass", "C:\\");
#else
CFtpServer::UserNode *FtpUser = FtpServer.AddUser( "test", "pass", "/");
#endif
if( FtpUser ) {
printf("-FtpUser successfuly created ! :)\r\n");
FtpServer.SetUserMaxClient( FtpUser, CFtpServer::Unlimited );
FtpServer.SetUserPriv( FtpUser, CFtpServer::READFILE | CFtpServer::WRITEFILE | CFtpServer::LIST | CFtpServer::DELETEFILE | CFtpServer::CREATEDIR | CFtpServer::DELETEDIR );
#ifdef CFTPSERVER_USE_EXTRACMD // See CFtpServer.h, not defined by default
FtpServer.SetUserExtraCmd( FtpUser, CFtpServer::ExtraCmd_EXEC );
// Security Warning ! Only here for example.
// the last command allow the user to call the 'system()' C function!
#endif
if( FtpServer.StartListening() ) {
printf("-Server is listening ! :)\r\n");
if( FtpServer.StartAccepting() ) {
printf("-Server successfuly started ! :)\r\n");
while( 1 )
#ifdef WIN32
Sleep( 1000 );
#else
usleep( 1000 );
#endif
FtpServer.StopListening();
} else
printf("-Unable to accept incoming connections.\r\n");
} else
printf("-Unable to listen.\r\n");
} else printf("-Unable to create FtpUser.\r\n");
printf("-Exiting.\r\n");
system("pause");
return 0;
}
Conclusion :
voila un bon exemple.
Sinon, le code est bien optimisé niveau rapidité.
Niveau sécurité, ca m'étonnerai vraiment que y ai des problemes.
Voila, j'attend vos commentaires !
theBrowser
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.