コード例 #1
0
Value* DownloadModemFn(const char* name, State* state, int argc, Expr* argv[]) {

    char* modemImg;
    int result = -1;

    if (argc != 1)
        return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);

    if (ReadArgs(state, argv, 1, &modemImg) != 0) {
        return NULL;
    }

    printf("DownloadModemFn: %s\n", modemImg);

    result = DownloadFiles(modemImg);

    if (result < 0) {
        printf("Download failed!\n");
    } else {
        printf("Download success!\n");
        ResetModem();
        sleep(6);
    }
    return StringValue(strdup(result >= 0 ? "t" : ""));
}
コード例 #2
0
ファイル: dbconnection.cpp プロジェクト: muyun/dev.webservice
int _tmain(int argc, _TCHAR* argv[])
{
	//to test
	std::string object = "eyes";
	std::string suspect = "138216560533-88011_L_2_Eyelid.bmp";
	std::string subject = "138156374231-113AD-080GE__1_00-0C-DF-04-A2-2D2222_F4_L4.jpg";
	std::string camera = "06";
	std::string gate = "02";

	DownloadFiles(object);
	//UpdateData(object, suspect, subject, camera, gate);
	//UploadFile(subject);
}
コード例 #3
0
// ===============================================================
// ‘ункци¤ загрузки обновлени¤
void FtpDownload ( const std::wstring& serverName, const std::wstring& pathTo ) {

	// —оединение с сервером
	wprintf ( L"Connecting to server %s...\n", (L"ftp://" + serverName + L"/" + pathTo).c_str() );
	HINTERNET hInet = InternetOpenW( L"GameInc updater agent", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
	HINTERNET hFtp = InternetConnectW( hInet, serverName.c_str(), INTERNET_DEFAULT_FTP_PORT, L"anonymous", L"*****@*****.**", INTERNET_SERVICE_FTP, 0, 0 );
	if ( !hInet || !hFtp )
		wprintf( L"Server are not availble. Goodbay\n" );
	else
		if ( !DownloadFiles ( hFtp, pathTo ) )
			wprintf( L"Some errors while update\n" );

	// ќсвобождение ресурсов
	InternetCloseHandle( hFtp );
	InternetCloseHandle( hInet );
} // ThreadProc
コード例 #4
0
// ===============================================================
// —качивает файлы с FTP
bool DownloadFiles ( HINTERNET hFtp, const std::wstring& rootDir ) 
{
	//printf( "Resolve directory %s\n", rootDir.c_str() );

	char buf[1024] = {0};
	std::vector< std::wstring > dirs;
	DWORD c = 1024;
	WIN32_FIND_DATAW fd = { 0 }, ft = { 0 };

	if ( !FtpSetCurrentDirectoryW( hFtp, rootDir.c_str() ) )
		wprintf( ( L"Directory " + rootDir + L" are not avaible. Goodbay\n").c_str() );

	HINTERNET hSearch = FtpFindFirstFileW( hFtp, NULL, &fd, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD , 0 );
		
	if ( hSearch ) 
	{
		do 
		{
			if( wcscmp( fd.cFileName, L"." ) == 0 || wcscmp( fd.cFileName, L".." ) == 0 )
				continue;

			if ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
			{
				dirs.push_back( fd.cFileName );
			}
			
			else 
			{
				// —равниваем дату найденного файла с тем что сейчас в списке
				if ( _waccess( fd.cFileName, 0 ) == -1 ) 
				{
					wprintf( L"Loading file %s\n", fd.cFileName );
					if( !FtpGetFileW( hFtp, fd.cFileName, fd.cFileName, FALSE, 0, 0, 0 ) )
							  return false;
				}
				else
				{
					HANDLE ftFile = FindFirstFileW( fd.cFileName, &ft );
					if ( CompareFileTime ( &ft.ftLastWriteTime, &fd.ftLastWriteTime ) < 0 ) 
					{			
						wprintf( L"Loading file %s\n", fd.cFileName );
						if ( !FtpGetFileW( hFtp, fd.cFileName, fd.cFileName, FALSE, 0, 0, 0 ) )
							return false;
					}
				}
			}
		} while ( InternetFindNextFile ( hSearch, &fd ) );
		 
		InternetCloseHandle ( hSearch );
	}

	for( size_t k=0; k < dirs.size(); k++ )
	{
		CreateDirectoryW( dirs[ k ].c_str(), NULL );
		SetCurrentDirectoryW( dirs[ k ].c_str() );

		DownloadFiles( hFtp, dirs[ k ] );
	}
	
	FtpSetCurrentDirectoryW( hFtp, L".." );
	SetCurrentDirectoryW( L".." );
	return true;
}  // DownloadFiles