
#include "stdafx.h"
#include "CFtp.h"

C_FTP_0::C_FTP_0()
{
	_info = "Server";
}

bool C_FTP_0::Pripojit()
{
	DWORD dwFlags = 0;
	_SetInfo("Pripojuju se k serveru....");
	if( !InternetGetConnectedState(&dwFlags, 0) )
	{
		_SetInfo("Nenalezeno pripojeni k internetu");
		return FALSE;
	}

	_hInternet = InternetOpen("WEngine", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if( !_hInternet )
	{
		_SetInfo("Nepodarilo se vytvorit spojeni");
		return FALSE;
	}
	_ftpConnect = InternetConnect(_hInternet, "arc3d.wz.cz", INTERNET_DEFAULT_FTP_PORT, "arc3d.wz.cz", "11aa22bb", INTERNET_SERVICE_FTP, 0, NULL);
	if( !_ftpConnect )
	{
		_SetInfo("Nepodarilo se pripojit k serveru");
		return FALSE;
	}
	
	return TRUE;
}

bool C_FTP_0::Odpojit()
{
	if( !_ftpConnect )
	{
	_SetInfo("Uz je odpojeno");
		return FALSE;
	}
	
	if( !InternetCloseHandle(_ftpConnect) )
	{
		_SetInfo("Nejde se odpojit od serveru");
		return FALSE;
	}
	_SetInfo("Score odeslano");
	return TRUE;
}

bool C_FTP_0::CopyFile(std::string pathFile, std::string nameFile)
{
	if( !FtpPutFile(_ftpConnect, pathFile.c_str(), nameFile.c_str(), FTP_TRANSFER_TYPE_BINARY, 0) )
	{
		_SetInfo("Nejde nakopirovat soubor");
		return FALSE;
	}
	return TRUE;
}

bool C_FTP_0::LoadFile(std::string pathFile, std::string nameFile)
{
	if( !FtpGetFile(_ftpConnect, pathFile.c_str(), nameFile.c_str(), FALSE, 0, FTP_TRANSFER_TYPE_BINARY, 0) )
	{
		_SetInfo("Nejde nahrat soubor na ftp");
		return FALSE;
	}

	return TRUE;
}