예제 #1
0
파일: ofxFTP.cpp 프로젝트: Geistyp/ofxFTP
void ofxFTPServer::start(int port, string publish_dir, string username, string password)
{
	server.SetDataPortRange(10000, 12000);
	server.SetCheckPassDelay(500);
	server.EnableFXP(true);
	
	publish_dir = ofToDataPath(publish_dir, true);
	
	CFtpServer::CUserEntry *user = server.AddUser(username.c_str(), password.c_str(), publish_dir.c_str());
	user->SetMaxNumberOfClient(0);
	user->SetPrivileges(CFtpServer::READFILE | CFtpServer::WRITEFILE |
						CFtpServer::LIST | CFtpServer::DELETEFILE | CFtpServer::CREATEDIR |
						CFtpServer::DELETEDIR);
	
	if (server.StartListening(INADDR_ANY, port))
	{
		if (!server.StartAccepting())
			ofLogError("ofxFTPServer", "server couldn't start");
	}
	else
		ofLogError("ofxFTPServer", "port is already used");
}
예제 #2
0
파일: nodeftp.cpp 프로젝트: fredix/ncs
void Nodeftp::add_ftp_user(QString email)
{
    qDebug() << "Nodeftp::add_user : "******"/ftp/" + directory;
        if (!QDir(userdirectory).exists()) QDir().mkdir(userdirectory);


        CFtpServer::CUserEntry *pUser = FtpServer->AddUser( email.toAscii(), token.toAscii(), userdirectory.toAscii() );
        if( pUser )
        {
            printf( "-User successfully created ! :)\r\n" );
            pUser->SetMaxNumberOfClient( 5 ); // 0 Unlimited

    /*        pUser->SetPrivileges( CFtpServer::READFILE | CFtpServer::WRITEFILE |
                CFtpServer::LIST | CFtpServer::DELETEFILE | CFtpServer::CREATEDIR |
                CFtpServer::DELETEDIR );
    */

            pUser->SetPrivileges(CFtpServer::WRITEFILE | CFtpServer::READFILE | CFtpServer::LIST);

    #ifdef CFTPSERVER_ENABLE_EXTRACMD // See "CFtpServer/config.h". not defined by default
            pUser->SetExtraCommand( CFtpServer::ExtraCmd_EXEC );
            // Security Warning ! Only here for example.
            // the last command allow the user to call the 'system()' C function!
    #endif

        }
        else qErrnoWarning( "-Unable to create pUser" );
    }
    else qErrnoWarning( "-Failed to create user" );
}
예제 #3
0
void Widget::startServer()
{
	#ifdef WIN32
		//Initialize WINSOCK because CFTPServer needs it on Windows
		
		WSADATA WSAData;
		if( WSAStartup( MAKEWORD(1, 0), &WSAData) != 0 ) {
			//printf("-WSAStartup failure: WSAGetLastError=%d\r\n", WSAGetLastError() );
			QMessageBox::information(0, "Error", "Winsock error: " + WSAGetLastError());
			 //return 0;
		}
	#endif

	QString dir = qApp->applicationDirPath();

	if(QDir().exists("/Sync") == false)
	{
		QDir().mkdir(dir + "/Sync");
	}
	
	//Begin FTP Server Initialization
	ftpServer = new CFtpServer();
	ftpServer->SetDataPortRange(100, 900);

	CFtpServer::CUserEntry *FtpUser = ftpServer->AddUser("lanclient", "tseug", QString(dir + "/Sync").toAscii());
	ftpServer->AddUser("anonymous", NULL, "C:\\dir");

	if(FtpUser)
	{
		FtpUser->SetMaxNumberOfClient( 0 );
		FtpUser->SetPrivileges( CFtpServer::READFILE | CFtpServer::WRITEFILE |
								CFtpServer::LIST | CFtpServer::DELETEFILE | CFtpServer::CREATEDIR |
								CFtpServer::DELETEDIR );
	}
	else
	{
		writeLog("FTP Server Could Not Create User");
		sysIcon->showMessage("FTP Error", "No user could be created on the FTP Server. Login Not Possible", QSystemTrayIcon::Critical, 10000 );
		error();
	}
	if(ftpServer->StartListening(INADDR_ANY, 21))
	{
	   if(ftpServer->StartAccepting() == false)
		{
			writeLog("FTP Server Could Not Begin Accepting on Port 21. Code corruption or incompatible dll");
			sysIcon->showMessage("FTP Error", "FTP Server Couldn't start accepting connections.", QSystemTrayIcon::Critical, 10000 );
			error();
		}
	}
	else
	{
		writeLog("FTP Server Could Not Start Listening On Port 21. Check WINSOCK. This application does not support concurrent instances.");
		sysIcon->showMessage("FTP Error", "FTP Server Couldn't Listen on port 21. It may be in use already.", QSystemTrayIcon::Critical, 10000 );
		error();
	}

	/*
	End FTP Server Initialization
	All Files in the applications working directory are now availible through FTP with user "lanclient" with pass "tseug"
	*/

	client->setEnabled(false);
	udpSocket->bind(QHostAddress::Any, standardUdpPort, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
	connect(udpSocket, SIGNAL(readyRead()), this, SLOT(signalReceived()));

	//resize the mainWindow because we need a bigger interface for server mode
	mainWindow->resize(600, 500);

	//create the tab-widget that we parent the sub-windows too
	computerManager = new QTabWidget(mainWindow);
	computerManager->setGeometry(5, 70, 590, 430);

	primaryStatus = new QWidget(computerManager);
	ftpWindow = new QWidget(computerManager);
	serverDownload = new QPushButton(ftpWindow);
	serverDownload->setGeometry(20, 355, 545, 45);

	QObject::connect(serverDownload, SIGNAL(clicked()), this, SLOT(serverDownloadStart()));

	computersConnected = 0;

	ftpFiles = new QTreeWidget(ftpWindow);
	ftpFiles->setGeometry(0, 0, 580, 350);

	fileModel = new QTreeWidgetItem(0);

	computerNames.append("Files");

	ftpFiles->setHeaderLabels(computerNames);

	computerManager->addTab(primaryStatus, "Network Status");
	computerManager->addTab(ftpWindow, "File Control");

	mapper = new QSignalMapper(this);
	
	computerTable = new QTreeWidget(primaryStatus);
	computerTable->setGeometry(0, 0, 580, 400);
	
	QTreeWidgetItem * compModel = new QTreeWidgetItem(0);
	compModel->setText(0, "Name");
	compModel->setText(1,"Bytes Total");
	compModel->setText(2, "Active");
	
	computerTable->setHeaderItem(compModel);
	computerTable->setColumnCount(3);
	computerTable->setColumnWidth(0, 150);
	computerTable->setColumnWidth(1, 120);
	computerTable->setColumnWidth(2, 305);
	computerTable->show();
	
	timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(update()));

	fileWatcher = new QFileSystemWatcher(this);
	fileWatcher->addPath(dir + "/Sync");
	connect(fileWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(sendUpdate()));

	timer->start(tcpCheckRate);

	computerManager->show();
	updateFileTable();
}