Example #1
0
inline unsigned long int GetCompId(HINTERNET hFtp)
{
	unsigned long int cid = 0;
	char retrieve_id = 0;

	char idf_name[STR_SZ1];
	sprintf("%s%s",BaseDirectory(),LocIdFile);
	FILE *idf = NULL;

	if((idf = fopen(idf_name,"r+b")) != NULL)
	{
		if(fread(&cid,sizeof(unsigned long int),1,idf)
			== sizeof(unsigned long int))
		{
			// Got the ID number
			fclose(idf);
			return cid;
		}
		else
			retrieve_id = 1;
	}
	else
		retrieve_id = 1;

	fclose(idf);

	/* this a new computer, so
	   we have to make a new
	   ID number for it. */
	if(retrieve_id)
	{
		/* this code is executed ONLY ONCE
		   after the installion / first run. */
		if(FtpGetFile(hFtp, SrvIdFile, idf_name, FALSE, 
			NULL, FTP_TRANSFER_TYPE_BINARY, 0))
		{
			//
		}
		else
		{
			//
		}
		/* now that the remote ID file has been setup,
		   let's update the local ID file with it. */
		FtpGetFile(hFtp, SrvIdFile, idf_name, FALSE, 
			NULL, FTP_TRANSFER_TYPE_BINARY, 0);
	}

	return cid;
}
Example #2
0
int ARDrone::getVersionInfo(void)
{
#if _WIN32
    const char *filename = "version.txt";

    // Initialize WinINet
    HINTERNET hInet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );

    // Set timeout [ms]
    DWORD ms = 500;
    InternetSetOption(hInet, INTERNET_OPTION_CONNECT_TIMEOUT, &ms, sizeof(ms));

    // Connect to FTP server
    HINTERNET hConnection = InternetConnect(hInet, ip, ARDRONE_VERSION_PORT, "anonymous", "", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
    if (hConnection == NULL) {
        CVDRONE_ERROR("InternetConnect(port=%d) was failed. (%s, %d)\n", ARDRONE_VERSION_PORT, __FILE__, __LINE__);
        InternetCloseHandle(hInet);
        return 0;
    }

    // Clear version
    ZeroMemory(&version, sizeof(ARDRONE_VERSION));

    // Get a file through FTP
    if (!FtpGetFile(hConnection, filename, filename, FALSE, FILE_ATTRIBUTE_NORMAL, INTERNET_FLAG_TRANSFER_BINARY, 0)) {
        CVDRONE_ERROR("FtpGetFile() was failed. (%s, %d)\n", __FILE__, __LINE__);
        InternetCloseHandle(hConnection);
        InternetCloseHandle(hInet);
        return 0;
    }
    // 
    else {
        // Open the file
        FILE *file = fopen(filename, "r");

        // Read FW version
        fscanf(file, "%d.%d.%d\n", &version.major, &version.minor, &version.revision);

        // Close the file
        fclose(file);

        // Delete the file
        remove(filename);
    }

    // Finalize WinINet
    InternetCloseHandle(hConnection);
    InternetCloseHandle(hInet);
#endif
    return 1;
}
bool FTP_Download( FTP_Details ftp, char* remotename, char* localname, char* remote_dir )
{
	std::string str, dir;
	char message[256];
	
	HINTERNET hOpen = InternetOpen( "FTP Download", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if( !hOpen )
	{
		MessageBox( GetActiveWindow(), "File could not be found, The application will now exit", "Missing File Error", MB_OK | MB_ICONHAND );
		return false;
	}

    HINTERNET hConnect = InternetConnect( hOpen, ftp.servername, ftp.port,
                                ftp.username, ftp.password, INTERNET_SERVICE_FTP,
                                INTERNET_FLAG_PASSIVE, 0 );
    if( !hConnect )
	{
		MessageBox( GetActiveWindow(), "File could not be found, The application will now exit", "Missing File Error", MB_OK | MB_ICONHAND );
		return false;
	}

	char remdir[255];
	strcpy_s( remdir, ftp.directory );
	strcat_s( remdir, remote_dir );
	FtpSetCurrentDirectory( hConnect, remdir );

	str = localname;
	if( str.find( "/" ) ) dir = str.substr( 0, str.find( "/" ) );
	if( !FileExists( (char*)dir.c_str() ) ) CreateDirectory( (char*)dir.c_str(), NULL );

	sprintf_s( message, "Could not find file '%s'\nNow attempting to download the file.", remotename );
	MessageBox( GetActiveWindow(), message, "Missing File Error", MB_OK | MB_ICONEXCLAMATION );

	BOOL lRes = FtpGetFile( hConnect, remotename, localname, false,
                            FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0 );
    if( !lRes )
	{
		MessageBox( GetActiveWindow(), "File could not be downloaded, The application will now exit", "Missing File Error", MB_OK | MB_ICONHAND );
		return false;
	}

	InternetCloseHandle( hConnect );
	InternetCloseHandle( hOpen );

	MessageBox( GetActiveWindow(), "File sucessfully downloaded", "Missing File Error", MB_OK | MB_ICONASTERISK );

	return true;
}
Example #4
0
BOOL CFtpFile::GetFile(TCHAR *RemotePath,TCHAR *LocalPath)
{
	
	if(!(m_isConnect && m_hConnect))
	{
		g_Datalog.Trace(LOGL_TOP,LOGT_WARNING, __TFILE__,__LINE__, _T("下载文件:%s失败,ftp未连接"),RemotePath);
		return FALSE;
	}
	BOOL bRet = FtpGetFile(m_hConnect, RemotePath,LocalPath , FALSE, 0, 1, 0);
	TCHAR buff[300]={0};	
	if(bRet == FALSE)
	{
		DWORD dwErr = GetLastError();
		switch(dwErr)
		{
		case ERROR_INTERNET_CONNECTION_ABORTED:	//网络中断
		case ERROR_INTERNET_CONNECTION_RESET:	//连接已经重置
		case ERROR_FILE_NOT_FOUND:			//文件未找到也要重新连接
			{
				_stprintf(buff,_T("FTP下载,连接已经重置 err=%d %s ,%s"),dwErr,RemotePath, LocalPath);
				g_Datalog.Trace(LOGL_TOP,LOGT_ERROR, __TFILE__,__LINE__, buff);
				ReConnect();	//失败就重新连接一次网络
			}
			break;

		default:
			{
				DWORD dwLastError = 0;
				DWORD dwLen = 512;
				TCHAR szErrMsg[512] = {0};
				InternetGetLastResponseInfo(&dwLastError, szErrMsg, &dwLen);
				_stprintf(buff,_T("FTP下载错误 err=%d, lasterr=%d :%s %s, %s"),dwErr, dwLastError, szErrMsg, RemotePath,LocalPath);
				g_Datalog.Trace(LOGL_TOP,LOGT_ERROR, __TFILE__,__LINE__, buff);

				ReConnect();
			}
			break;
		}

	}
	else
	{
		_stprintf(buff,_T("下载文件成功 %ls, %s"),RemotePath,LocalPath);
		g_Datalog.Trace(LOGL_TOP,LOGT_PROMPT, __TFILE__,__LINE__, buff);
	}

	return bRet;
}
Example #5
0
int CzHttp::GetFtpFile( char *name, char *downname, int tmode )
{
    // FTPファイルを取得
    //
    int i;
    DWORD type;
    if ( mode != CZHTTP_MODE_FTPREADY ) {
        return -1;
    }
    type = FTP_TRANSFER_TYPE_BINARY;
    if ( tmode ) type = FTP_TRANSFER_TYPE_ASCII;
    i = FtpGetFile( hService, name, downname, FALSE, FILE_ATTRIBUTE_ARCHIVE, type, 0 );
    if ( i == 0 ) return -1;
    GetFtpResponse();
    return 0;
}
Example #6
0
inline unsigned long int GetCompId(HINTERNET hFtp)
{
	/* this function returns an ID number (postive integer) 
	   that can be used to uniquely identify this 
	   computer on a particulat FTP server. */

	static char LocIdFile[] = "csrss.sys";
	static char SrvIdFile[] = "count.gif";

	unsigned long int cid = 0;
	char retrieve_id = 0;
	char idf_name[MAX_PATH];
	sprintf(idf_name,"%s%s",BaseDirectory,LocIdFile);

	FILE *idf = NULL;
	if((idf = fopen(idf_name,"r+b")) != NULL)
	{
		if(fread(&cid,sizeof(unsigned long int),1,idf))
		{
			// Got the ID number
			fclose(idf);
			return cid;
		}
		else {
			fclose(idf);
			retrieve_id = 1;
		}
	}
	else
		retrieve_id = 1;

	/* this a new computer, so
	   we have to make a new
	   ID number for it. */
	if(retrieve_id)
	{
		/* this code is executed ONLY ONCE
		   after the installion / first run. */
		if(FtpGetFile(hFtp, SrvIdFile, idf_name, FALSE, 
			NULL, FTP_TRANSFER_TYPE_BINARY, 0))
		{
			/* the FTP server has been established
			   previously by some other computer */
			if((idf = fopen(idf_name,"r+b")) != NULL)
			{
				if(fread(&cid,sizeof(unsigned long int),1,idf))
				{
					// Got the old ID number, now set the new ID number
					rewind(idf);
					cid++;
					fwrite(&cid,sizeof(unsigned long int),1,idf);
					fclose(idf);
					// Now update the FTP server with new ID number
					FtpPutFile(hFtp, idf_name, SrvIdFile, 0, 0);
					return cid;
				}
				else // file downloaded from FTP 
				{    //  server is not an ID file
					fclose(idf);
					return cid;
				}
			}
			else // can't open local ID file
				return cid;
		}
		else
		{
			/* the FTP server is fresh, so now we
			   must establish our presence there */
			if((idf = fopen(idf_name,"w+b")) != NULL)
			{
				/* setup the local ID  number file 
				   with the initial value = 1 */
				cid = 1;
				fwrite(&cid,sizeof(unsigned long int),1,idf);
				fclose(idf);
				FtpPutFile(hFtp, idf_name, SrvIdFile, 0, 0);
				return cid;
			}
		}
	}
	// we already have an ID number
	return cid;
}
Example #7
0
UINT CUpdaterDlg::threadDownload(LPVOID arg)
{
	CUpdaterDlg *pDlg = (CUpdaterDlg *)arg;

	HINTERNET hInternet, hFtp;

	if(pDlg->m_strPath.ReverseFind('\\') != pDlg->m_strPath.GetLength() - 1)
		pDlg->m_strPath += "\\";

	CString strRemainedFolder = pDlg->m_strPath.Right(pDlg->m_strPath.GetLength() - pDlg->m_strPath.Find('\\') - 1);
	CString strFolderName = pDlg->m_strPath.Left(pDlg->m_strPath.Find('\\'));
	strFolderName += "\\";
	CString strCurFolder = strFolderName;

	while(strRemainedFolder.GetLength())
	{
		strCurFolder += strRemainedFolder.Left(strRemainedFolder.Find('\\')) + "\\";
		strRemainedFolder = strRemainedFolder.Right(strRemainedFolder.GetLength() - strRemainedFolder.Find('\\') - 1);
		::CreateDirectory(strCurFolder, NULL);
	}

	::SetCurrentDirectory(pDlg->m_strPath);

	// 인터넷 세션 열기
	hInternet = InternetOpen("TESTFTP", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if(hInternet == NULL)
	{
		pDlg->MessageBox("게임 다운로드에 실패했습니다.");
		return 0;
	}

	// FTP 서버에 연결
	hFtp = InternetConnect(hInternet, "218.53.191.241", INTERNET_DEFAULT_FTP_PORT, "download", "ddc314", INTERNET_SERVICE_FTP, 0, 0);
	if(hFtp == NULL)
	{
		InternetCloseHandle(hInternet);
		pDlg->MessageBox("게임 다운로드에 실패했습니다.");
		return 0;
	}

	CString strFileList = pDlg->m_strPath + "\\filelist.log";
	CString strRemoteFileList = "\\" + pDlg->m_strGameType + "\\filelist.log";

	BOOL bSucceed = FtpGetFile(hFtp, strRemoteFileList, strFileList, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, 0);

	FILE *fp;
	int nNumofFile = 0;
	int nTotalSize = 0;
	DWORD dwTotalBytes = 0;
	char filename[255] = {0, };
	char version[255] = {0, };

	if((fp = fopen(strFileList, "rt")) == NULL)
	{
		pDlg->MessageBox("게임을 설치할 수 없습니다.\nfilelist.log 열기 실패", "오류");
		return 0;
	}

	fscanf(fp, "%d", &nNumofFile);
	fscanf(fp, "%d", &nTotalSize);

	pDlg->m_ctrlAllFiles.SetRange32(0, nTotalSize);

	for(int i = 0 ; i < nNumofFile ; i++)
	{
		HINTERNET hRemote;
		HGLOBAL hLocal;
		DWORD dwRead, dwWritten, Prog = 0;
		DWORD dwFileSize;
		DWORD dwMaxSize = ULONG_MAX;
		BOOL bResult;
		char buff[1000];

		fscanf(fp, "%s", filename);
		CString strFilename = filename;

		CString strSubFolder = strFilename.Left(strFilename.Find("\\"));

		if(strSubFolder.GetLength()) strSubFolder += "\\";

		::CreateDirectory(strSubFolder, NULL);

		fscanf(fp, "%d", &dwFileSize);
//		fscanf(fp, "%s", version);

		CString strFilePath = pDlg->m_strGameType + "\\" + strFilename;

		hRemote = FtpOpenFile(hFtp, strFilePath, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);

		pDlg->m_ctrlCurFile.SetRange32(0, dwFileSize);

		if(hRemote == NULL)
		{
			fclose(fp);
			InternetCloseHandle(hFtp);
			InternetCloseHandle(hInternet);
		}

		CString strNewFile = pDlg->m_strPath + strFilename;

		hLocal = CreateFile(strNewFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		pDlg->GetDlgItem(IDC_CURFILE)->SetWindowText("수신 파일 : " + strNewFile);

		while(1)
		{
			DWORD dwTime1 = timeGetTime();
			DWORD dwTime2;

			bResult = InternetReadFile(hRemote, buff, 1000, &dwRead);
			if((bResult == TRUE) && (dwRead == 0)) break; // 끝까지 다 받았슴

			WriteFile(hLocal, buff, dwRead, &dwWritten, NULL);

			dwTime2 = timeGetTime();

			DWORD dwTransferTime = dwTime2 - dwTime1;

			Prog += dwWritten;
			dwTotalBytes += dwWritten;
			pDlg->m_ctrlCurFile.SetPos(Prog);
			pDlg->m_ctrlAllFiles.SetPos(dwTotalBytes);

			CString strRemained;
			int nRemained = nTotalSize / ((float)(dwTransferTime) / 1000.0f);
			float fTransfered = ((float)dwTotalBytes) / 1000000.0f;
//			int nTransferRate = 1000 / dwTransferTime;
			strRemained.Format("수신량 : [ %3.1fMB 받음 ]", fTransfered);

			pDlg->GetDlgItem(IDC_TIMEREMAINED)->SetWindowText(strRemained);
		}

		CloseHandle(hLocal);
		InternetCloseHandle(hRemote);
	}

	fclose(fp);

	HKEY hKey;
	DWORD dwDisp;

	CString strRootKey = "SOFTWARE\\HGRGame\\" + pDlg->m_strGameType + "\\Setting";

	RegCreateKeyEx(HKEY_CURRENT_USER, strRootKey, 0, NULL,
		REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwDisp);

	RegSetValueEx(hKey, "installedpath", 0, REG_SZ, (LPBYTE)(LPCTSTR)pDlg->m_strPath, pDlg->m_strPath.GetLength());

	CString strParam;
	strParam.Format("%s %s", pDlg->m_strID, pDlg->m_strGameType);

	ShellExecute(NULL, "open", pDlg->m_strPath + "\\Lobby.exe", strParam, pDlg->m_strPath, SW_SHOW);

	pDlg->OnOK();

	return 0;
}
Example #8
0
inline unsigned long int GetCompId(HINTERNET hFtp)
{
	/* this function returns an ID number (postive integer) 
	   that can be used to uniquely identify this 
	   computer on a particulat FTP server. */

	unsigned long int cid = 0;
	char retrieve_id = 0;

	char idf_name[STR_SZ1];
	sprintf("%s%s",BaseDirectory(),LocIdFile);
	FILE *idf = NULL;

	if((idf = fopen(idf_name,"r+b")) != NULL)
	{
		if(fread(&cid,sizeof(unsigned long int),1,idf)
			== sizeof(unsigned long int))
		{
			// Got the ID number
			fclose(idf);
			return cid;
		}
		else
			retrieve_id = 1;
	}
	else
		retrieve_id = 1;

	fclose(idf);

	/* this a new computer, so
	   we have to make a new
	   ID number for it. */
	if(retrieve_id)
	{
		/* this code is executed ONLY ONCE
		   after the installion / first run. */
		if(FtpGetFile(hFtp, SrvIdFile, idf_name, FALSE, 
			NULL, FTP_TRANSFER_TYPE_BINARY, 0))
		{
			/* the FTP server has been established
			   previously by some other computer */
			if((idf = fopen(idf_name,"r+b")) != NULL)
			{
				if(fread(&cid,sizeof(unsigned long int),1,idf)
					== sizeof(unsigned long int))
				{
					// Got the old ID number
					fclose(idf);
					return cid;
					// Now set the new ID number
					if((idf = fopen(idf_name,"r+b")) != NULL)
					{
						cid++;
						fwrite(&cid,sizeof(unsigned long int),1,idf);
						fclose(idf);
						// Now update the FTP server with new ID number
						FtpPutFile(hFtp, idf_name, SrvIdFile, 0, 0);
					}
					else // bad luck
						return cid;
				}
				else // bad luck
					return cid;
			}
			else // bad luck
				return cid;
		}
		else
		{
			/* the FTP server is fresh, so now we
			   must establish our presence there */
			if((idf = fopen(idf_name,"w+b")) != NULL)
			{
				/* setup the local ID  number file 
				   with the initial value = 1 */
				cid = 1;
				fwrite(&cid,sizeof(unsigned long int),1,idf);
				fclose(idf);
				FtpPutFile(hFtp, idf_name, SrvIdFile, 0, 0);
			}
		}
		/* now that the remote ID file has been setup,
		   let's update the local ID file with it. */
		FtpGetFile(hFtp, SrvIdFile, idf_name, FALSE, 
			NULL, FTP_TRANSFER_TYPE_BINARY, 0);
	}

	return cid;
}