Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Clarify Pin
Anonymous16-Jan-03 4:58
Anonymous16-Jan-03 4:58 
GeneralRe: Clarify Pin
Cris16-Jan-03 5:15
Cris16-Jan-03 5:15 
GeneralRe: Clarify Pin
16-Jan-03 5:16
suss16-Jan-03 5:16 
GeneralRe: Clarify Pin
Cris16-Jan-03 5:46
Cris16-Jan-03 5:46 
GeneralUsing a Dialog Box that is defined inside a dll. Pin
VanHlebar16-Jan-03 2:18
VanHlebar16-Jan-03 2:18 
GeneralCreateProcessAsUser(...) & LogonUser bug!!!!!!!!! Pin
r i s h a b h s16-Jan-03 2:02
r i s h a b h s16-Jan-03 2:02 
GeneralFTP problem with MFC Pin
Anonymous16-Jan-03 1:25
Anonymous16-Jan-03 1:25 
GeneralRe: FTP problem with MFC Pin
Ted Ferenc16-Jan-03 2:50
Ted Ferenc16-Jan-03 2:50 
Here is a code snipped of how I do it, Note fileFound is a virtual method used by the derived class to do all the work.

Hope it helps, the code is just a quick hack, and not very tidy, as it implies it is recursive. I use it to do a tree delete on my FTP server.

void CFTPDirWalk::DirWalkRecurse(TCHAR* szFilename)
{
	BOOL			bKilled		= FALSE,
					bOK			= FALSE;

//	CFtpFileFind	findFile(m_pFTPConnect);

	CObArray		objArray;

	CString		strDirPath	= _T(""),		// Store the current dir path
					strBuffer	= _T("");

	DWORD			dwLength			= 0,
					dwWaitResult	= 0;

	HINTERNET	hFileFound		= NULL;

	TCHAR			szBuffer[MAX_PATH + 1];

	WIN32_FIND_DATA		FindData;
	WIN32_FIND_DATA		*pFindData	= NULL;

	int			nIndex		= 0,
					nLoop			= 0,
					nSlash		= 0;

	objArray.SetSize(0);

	dwLength = MAX_PATH;

	FtpGetCurrentDirectory(m_hFTPConnect, szBuffer, &dwLength);
		// Use a counter to stop deleting the start dir
	m_dwRecureCounter++;

		// Add the file path to the name, the '/' or '\' might not be there!
	strDirPath = szBuffer;
	nSlash = strDirPath.GetLength() - 1;
	if(nSlash > 0)
		if(strDirPath.GetAt(nSlash) != '/')
			strDirPath += "/";

		// Find all the files
//	bOK = findFile.FindFile(szFilename);

	hFileFound = FtpFindFirstFile(m_hFTPConnect, szFilename, &FindData, INTERNET_FLAG_RELOAD, 2);
	bOK = hFileFound ? TRUE : FALSE;

	while(bOK && !bKilled) 
		{
			// Has the termination flag been set?
		dwWaitResult = WaitForSingleObject(m_hCloseDown, 0);
		bKilled = dwWaitResult == WAIT_OBJECT_0 ? TRUE : FALSE;
		if(bKilled)
			continue;
			
//		bOK = findFile.FindNextFile();

			// Store the file data
		if(!isDots(&FindData))
			{
			int nSize = sizeof(WIN32_FIND_DATA);
			pFindData = (WIN32_FIND_DATA*) new WIN32_FIND_DATA;
			ZeroMemory(pFindData, sizeof(WIN32_FIND_DATA));
			CopyMemory(pFindData, &FindData, sizeof(WIN32_FIND_DATA));

				// Build up the name, findFile.GetFilePath() gives NBG name
				// M$ does not store the path, but we do!
			sprintf(pFindData->cFileName, "%s%s", strDirPath, FindData.cFileName );
//			_tcscpy(pFindData->cFileName, findFile.GetFilePath());
			objArray.SetAtGrow(nIndex++, (CObject*) pFindData);
			}
			// Has to be done at the end, as FtpFindFirstFile does actually
			// find the first file details
		bOK = InternetFindNextFile(hFileFound, &FindData);
		}

	InternetCloseHandle(hFileFound);
//	findFile.Close();

		// Now loop, if a dir then attach to it and recurse
	for(nLoop = 0; nLoop < objArray.GetSize() && !bKilled; nLoop++)
		{
		pFindData = (WIN32_FIND_DATA*) objArray.GetAt(nLoop);
			// Just in case!
		if(!pFindData)
			continue;

		if((pFindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				// CWD and check if OK
			if(FtpSetCurrentDirectory(m_hFTPConnect, (LPCSTR) pFindData->cFileName))
				{
				dwLength = MAX_PATH;
				DirWalkRecurse(szFilename);
				}
			}
		else
			{
				// Call virtual method
			fileFound(pFindData, m_hFTPConnect);
			}
		}
		// Don't delete/display the home dir
	if(--m_dwRecureCounter > 0 && !bKilled)
		{
			// Build up a WIN32_FIND_DATA for the directory
		ZeroMemory(&FindData, sizeof(WIN32_FIND_DATA));
		sprintf(FindData.cFileName, strDirPath);
		FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;

		dirFoundExit(&FindData, m_hFTPConnect);
		}

		// Tidy up
	for(nLoop = 0; nLoop < objArray.GetSize(); nLoop++)
		{
		pFindData = (WIN32_FIND_DATA*) objArray.GetAt(nLoop);
		if(pFindData)
			delete pFindData;
		}
}




If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
GeneralRe: FTP problem with MFC Pin
Anonymous16-Jan-03 3:38
Anonymous16-Jan-03 3:38 
GeneralRe: FTP problem with MFC Pin
Ted Ferenc16-Jan-03 3:55
Ted Ferenc16-Jan-03 3:55 
GeneralRe: FTP problem with MFC Pin
Anonymous16-Jan-03 4:24
Anonymous16-Jan-03 4:24 
GeneralRe: FTP problem with MFC Pin
Ted Ferenc16-Jan-03 6:34
Ted Ferenc16-Jan-03 6:34 
GeneralRe: FTP problem with MFC Pin
Anonymous17-Jan-03 3:55
Anonymous17-Jan-03 3:55 
GeneralRe: FTP problem with MFC Pin
Ted Ferenc17-Jan-03 3:58
Ted Ferenc17-Jan-03 3:58 
Generalopen and close ports!!!!!! Pin
xxhimanshu16-Jan-03 1:11
xxhimanshu16-Jan-03 1:11 
GeneralAccessing password protected web sites Pin
Christoffer A. Andersen16-Jan-03 0:14
Christoffer A. Andersen16-Jan-03 0:14 
GeneralRe: Accessing password protected web sites Pin
Steve S16-Jan-03 2:21
Steve S16-Jan-03 2:21 
GeneralRe: Accessing password protected web sites Pin
Christoffer A. Andersen16-Jan-03 2:27
Christoffer A. Andersen16-Jan-03 2:27 
GeneralTHIS_FILE and __FILE__ Pin
-Dy15-Jan-03 23:56
-Dy15-Jan-03 23:56 
GeneralRe: THIS_FILE and __FILE__ Pin
Joaquín M López Muñoz16-Jan-03 0:03
Joaquín M López Muñoz16-Jan-03 0:03 
GeneralRe: THIS_FILE and __FILE__ Pin
Rage16-Jan-03 1:10
professionalRage16-Jan-03 1:10 
GeneralWindows Timing performance Pin
Geert Craessaerts15-Jan-03 23:36
Geert Craessaerts15-Jan-03 23:36 
GeneralRe: Windows Timing performance Pin
Joel Lucsy16-Jan-03 3:26
Joel Lucsy16-Jan-03 3:26 
GeneralCapture the Packet Pin
summo15-Jan-03 23:29
summo15-Jan-03 23:29 
GeneralCapture the Packet Pin
summo15-Jan-03 23:26
summo15-Jan-03 23:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.