Exemple #1
0
void CzHttp::GetFtpDirList( void )
{
    // FTPカレントディレクトリ内容を取得
    //
    if ( mode != CZHTTP_MODE_FTPREADY ) {
        return;
    }
    ResetFlexBuf( 1024 );
    hFtpEnum = FtpFindFirstFile( hService, NULL, &finddata, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, 0 );
    if ( hFtpEnum != NULL ) mode = CZHTTP_MODE_FTPDIR;
}
Exemple #2
0
fsInternetResult fsFtpFiles::BuildList()
{
	fsInternetResult ir = IR_SUCCESS;
	
	WIN32_FIND_DATA wfd;

	m_vFiles.clear ();

	if (m_bAbort)
		return IR_S_FALSE;

	
	HINTERNET hFind = FtpFindFirstFile (m_pServer->GetHandle (), NULL, &wfd, m_bReload ? INTERNET_FLAG_RELOAD : 0, NULL);

	if (hFind)
	{
		do
		{
			fsFileInfo file;

			if (_tcscmp (wfd.cFileName, _T(".")) == 0 || _tcscmp (wfd.cFileName, _T("..")) == 0)
				continue;

			file.strName = wfd.cFileName;
			file.uSize = wfd.nFileSizeLow;
			file.date = wfd.ftLastWriteTime;
			file.bAvailable = TRUE;
			file.bFolder = wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;

			if (file.strName == NULL)
			{
				InternetCloseHandle (hFind);
				return IR_OUTOFMEMORY;
			}

			
			m_vFiles.add (file);
		}
		while (InternetFindNextFile (hFind, &wfd) && m_bAbort == FALSE);

		if (::GetLastError () != ERROR_NO_MORE_FILES && m_bAbort == FALSE)
			ir = fsWinInetErrorToIR ();

		InternetCloseHandle (hFind);
	}

	if (m_bAbort)
		m_vFiles.clear ();

	return m_bAbort ? IR_S_FALSE : ir;
}
Exemple #3
0
    bool FtpClient::FirstFile(const char *filename, FtpFileInformation & info)
    {
        if (m_hConnect == 0)
            return false;

        CloseFind();

        m_hFind = (HINTERNET )FtpFindFirstFile(m_hConnect, filename, &m_findData, INTERNET_FLAG_DONT_CACHE, 0);
        if (m_hFind == NULL)
            return false;

        UpdateFileInformation(info);

        return true;
    }
Exemple #4
0
int FTP::GetFindData(PluginPanelItem **pPanelItem, int *pItemsNumber, int OpMode)
{
	PROC(("FTP::GetFindData",NULL))
	DWORD        b,e;
	char            *Data[3];
	*pPanelItem   = NULL;
	*pItemsNumber = 0;

//Hosts
	if(ShowHosts)
	{
		EnumHost        Enum(HostsPath);
		FP_SizeItemList il(FALSE);
		PluginPanelItem tmp;
		FTPHost         h;

		if(!IS_SILENT(OpMode))
		{
			memset(&tmp, 0, sizeof(tmp));
			strcpy(tmp.FindData.cFileName,"..");
			tmp.FindData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;

			if(!IS_SILENT(OpMode))
			{
				tmp.Description               = (char *)"..";
				tmp.CustomColumnNumber        = 3;
				tmp.CustomColumnData          = Data;
				tmp.CustomColumnData[0]       = (char *)"..";
				tmp.CustomColumnData[1]       = (char *)"..";
				tmp.CustomColumnData[2]       = (char *)"..";
			}

			if(!il.Add(&tmp))
				return FALSE;
		}

		while(true)
		{
			if(!Enum.GetNextHost(&h))
				break;

			if(!h.Read(NULL))
				continue;

			memset(&tmp, 0, sizeof(tmp));
			/* Panel item MUST have name the save as file saved to disk
			   in case you want to copy between panels work.
			*/
			h.MkINIFile(tmp.FindData.cFileName,NULL,"");
			tmp.FindData.ftLastWriteTime  = h.LastWrite;
			tmp.FindData.dwFileAttributes = h.Folder ? FILE_ATTRIBUTE_DIRECTORY : 0;
			tmp.Flags                     = PPIF_USERDATA;
			tmp.PackSizeHigh              = FTP_HOSTID;
			tmp.UserData                  = (DWORD_PTR)&h;

			if(!IS_SILENT(OpMode))
			{
				tmp.Description               = h.HostDescr;
				tmp.CustomColumnNumber        = 3;
				tmp.CustomColumnData          = Data;
				tmp.CustomColumnData[0]       = h.Host;  //C0
				tmp.CustomColumnData[1]       = h.Home;  //C1
				tmp.CustomColumnData[2]       = h.User;  //C2
			}

			if(!il.Add(&tmp))
				return FALSE;

			Log(("Item[%d]=[%s] attr=%08X",
			     il.Count()-1, FTP_FILENAME(il.Item(il.Count()-1)),
			     il.Item(il.Count()-1)->FindData.dwFileAttributes));
		}

		*pPanelItem   = il.Items();
		*pItemsNumber = il.Count();
		return TRUE;
	}

//FTP
	FP_Screen _scr;
	FTPFileInfo FileInfo;

	if(!hConnect)
	{
		goto AskConnect;
	}

Restart:

	if(!FtpFindFirstFile(hConnect, "*", &FileInfo, &ResetCache))
	{
		if(GetLastError() == ERROR_NO_MORE_FILES)
		{
			*pItemsNumber = 0;
			return TRUE;
		}

		if(SwitchingToFTP && GetLastError() == ERROR_CANCELLED)
		{
			;
		}
		else
		{
			if(CurrentState == fcsExpandList)
			{
				FreeFindData(*pPanelItem,*pItemsNumber);
				*pPanelItem   = NULL;
				*pItemsNumber = 0;
				return FALSE;
			}

//Query reconnect
			do
			{
				if(!hConnect)
					break;

				if(GetLastError() == ERROR_CANCELLED)
					break;

				if(!hConnect->ConnectMessageTimeout(MConnectionLost,Host.HostName,-MRestore))
				{
					Log(("WaitMessage cancelled"));
					break;
				}

				if(FtpCmdLineAlive(hConnect) &&
				        FtpKeepAlive(hConnect))
					goto Restart;

				if(SelectFile.Length() && CurrentState != fcsExpandList)
					SaveUsedDirNFile();

AskConnect:

				if(Connect())
					goto Restart;
				else
					break;
			}
			while(true);
		}

		if(!ShowHosts)
			BackToHosts();

		FreeFindData(*pPanelItem, *pItemsNumber);
		return GetFindData(pPanelItem,pItemsNumber,OpMode);
	}

	GET_TIME(b);

	do
	{
		if(Opt.ShowIdle)
		{
			char str[ 200 ];
			GET_TIME(e);

			if(CMP_TIME(e,b) > 0.5)
			{
				_snprintf(str,ARRAYSIZE(str),"%s%d", FP_GetMsg(MReaded), *pItemsNumber);
				SetLastError(ERROR_SUCCESS);
				IdleMessage(str,Opt.ProcessColor);
				b = e;

				if(CheckForEsc(FALSE))
				{
					SetLastError(ERROR_CANCELLED);
					return FALSE;
				}
			}
		}

		PluginPanelItem *NewPanelItem=*pPanelItem;

		if((*pItemsNumber % 1024) == 0)
		{
			if(!NewPanelItem)
				NewPanelItem = (PluginPanelItem *)malloc((1024+1)*sizeof(PluginPanelItem));
			else
				NewPanelItem = (PluginPanelItem *)realloc(NewPanelItem,(*pItemsNumber+1024+1)*sizeof(PluginPanelItem));

			if(NewPanelItem == NULL)
			{
				/*-*/Log(("GetFindData(file)::!reallocate plugin panels items %d -> %d",*pItemsNumber,*pItemsNumber+1024+1));
				return FALSE;
			}

			*pPanelItem=NewPanelItem;
		}

		PluginPanelItem *CurItem = &NewPanelItem[*pItemsNumber];
		memset(CurItem, 0, sizeof(PluginPanelItem));
		CurItem->FindData = FileInfo.FindData;

		if(!IS_SILENT(OpMode))
		{
			CurItem->CustomColumnNumber             = FTP_COL_MAX;
			CurItem->Owner                          = FileInfo.FTPOwner[0] ? strdup(FileInfo.FTPOwner) : NULL;
			CurItem->CustomColumnData               = (LPSTR*)malloc(sizeof(LPSTR*)*FTP_COL_MAX);
			CurItem->CustomColumnData[FTP_COL_MODE] = strdup(FileInfo.UnixMode);
			CurItem->CustomColumnData[FTP_COL_LINK] = strdup(FileInfo.Link);
			hConnect->ToOEM(CurItem->CustomColumnData[FTP_COL_LINK]);
		}

		(*pItemsNumber)++;
	}
	while(FtpFindNextFile(hConnect,&FileInfo));

	return TRUE;
}
Exemple #5
0
bool Downloader::scanFtpDir(FtpDir *ftpDir, tstring destsubdir)
{
    Url url(ftpDir->url);
    url.internetOptions = internetOptions;
    
    updateFileName(url.components.lpszUrlPath);
    
    if(!url.connect(internet))
    {
        storeError();
        return false;
    }
    
    if(!FtpSetCurrentDirectory(url.connection, url.components.lpszUrlPath))
    {
        storeError();
        return false;
    }
    
    list<tstring> dirs;
    WIN32_FIND_DATA fd;

    TRACE(_T("Scanning FTP dir %s:"), ftpDir->url.c_str());
    HINTERNET handle = FtpFindFirstFile(url.connection, ftpDir->mask.c_str(), &fd, NULL, NULL);

    if(handle)
    {
        TRACE(_T("    (%s) %s"), (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _T("D") : _T("F"), fd.cFileName);
        updateFileName(tstring(fd.cFileName));

        if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            tstring dirname(fd.cFileName);

            if(!(dirname.compare(_T(".")) == 0) && !(dirname.compare(_T("..")) == 0))
                dirs.push_back(dirname);
        }
        else
        {
            tstring fileUrl  = addslash(ftpDir->url);
            tstring fileName = addbackslash(ftpDir->destdir);
            fileUrl  += tstring(fd.cFileName);
            fileName += addbackslash(destsubdir);
            fileName += tstring(fd.cFileName);
            
            addFile(fileUrl, fileName, ((DWORDLONG)fd.nFileSizeHigh << 32) | fd.nFileSizeLow, ftpDir->compstr);
        }

        while(InternetFindNextFile(handle, &fd))
        {
            TRACE(_T("    (%s) %s"), (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _T("D") : _T("F"), fd.cFileName);
            updateFileName(tstring(fd.cFileName));

            if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                tstring dirname(fd.cFileName);

                if(!(dirname.compare(_T(".")) == 0) && !(dirname.compare(_T("..")) == 0))
                    dirs.push_back(dirname);
            }
            else
            {
                tstring fileUrl  = addslash(ftpDir->url);
                tstring fileName = addbackslash(ftpDir->destdir);
                fileUrl  += tstring(fd.cFileName);
                fileName += addbackslash(destsubdir);
                fileName += tstring(fd.cFileName);
                
                addFile(fileUrl, fileName, ((DWORDLONG)fd.nFileSizeHigh << 32) | fd.nFileSizeLow, ftpDir->compstr);
            }
        }
    }

    url.disconnect();

    if(ftpDir->recursive && !dirs.empty())
    {
        for(list<tstring>::iterator i = dirs.begin(); i != dirs.end(); i++)
        {
            tstring dir = *i;

            tstring urlstr = addslash(ftpDir->url);
            urlstr += dir;
            FtpDir fdir(urlstr, ftpDir->mask, ftpDir->destdir, ftpDir->recursive, ftpDir->compstr);
            
            if(preserveFtpDirs)
            {
                tstring destdir(addbackslash(ftpDir->destdir));
                destdir += addbackslash(destsubdir);
                destdir += dir;
                TRACE(_T("Creating directory %s"), destdir.c_str());
                _tmkdir(destdir.c_str());

                tstring subdir = addbackslash(destsubdir);
                subdir += dir;
                scanFtpDir(&fdir, subdir);
            }
            else
                scanFtpDir(&fdir);
        }
    }

    return true;
}
void CSiteDir::ScanFTPFiles(BOOL bCheckExisting/* = FALSE*/)
{
	HINTERNET hFindFile;
	WIN32_FIND_DATA	wfd;

	TCHAR	search[MAX_PATH];
	wsprintf(search, "*.*", m_pathName);

	if (bCheckExisting)
	{
// Assume that all files have been deleted
		UPOSITION pos = m_childList.GetHeadPosition();
		while (pos)
		{
			CSiteItem* pItem = (CSiteItem*)m_childList.GetNext(pos);
			pItem->m_bFoundOnDisk = FALSE;
		}
	}

	if ((hFindFile = FtpFindFirstFile(
		m_pWebSite->m_hInternetFtp,
		search,
		&wfd,
		INTERNET_FLAG_RELOAD,
		0/*dwContext*/)) != NULL/*INVALID_HANDLE_VALUE*/)
	{
		do
		{
			if (wfd.cFileName[0] != '.')
			{
				CSiteItem* pExistingItem = NULL;

				if (bCheckExisting)
				{
					pExistingItem = FileExists(wfd.cFileName, (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? 1: 2);
					if (pExistingItem)
					{
						pExistingItem->m_bFoundOnDisk = TRUE;
					}
				}

				if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				{
					CSiteDir* pDir;

					if (pExistingItem)
					{
						pDir = (CSiteDir*)pExistingItem;
					}
					else
					{
						pDir = new CSiteDir;
						pDir->m_pWebSite = m_pWebSite;

						_makepath(pDir->m_pathName.GetBuffer(512), NULL, m_pathName, wfd.cFileName, NULL);
						pDir->m_pathName.ReleaseBuffer();
//						pDir->m_name = wfd.cFileName;
						pDir->m_wfd = wfd;
						pDir->m_bFoundOnDisk = TRUE;

						AddChildTail(pDir);

						pDir->AddSiteItemToDatabase();
					}

				//	pDir->ScanFiles(bCheckExisting);
				}
				else
				{
					if (pExistingItem)
					{
						CSiteFile* pFile = (CSiteFile*)pExistingItem;

						if (pFile->m_wfd.nFileSizeLow != wfd.nFileSizeLow ||
							pFile->m_wfd.nFileSizeHigh != wfd.nFileSizeHigh ||							
							pFile->m_wfd.dwFileAttributes != wfd.dwFileAttributes ||
							memcmp(&pFile->m_wfd.ftLastWriteTime, &wfd.ftLastWriteTime, sizeof(FILETIME)) ||
							memcmp(&pFile->m_wfd.ftCreationTime, &wfd.ftCreationTime, sizeof(FILETIME)))
						{
							pFile->m_wfd = wfd;
						}
					}
					else
					{
						CSiteFile* pFile = new CSiteFile;
						pFile->m_pWebSite = m_pWebSite;

						pFile->m_bFoundOnDisk = TRUE;
//						pFile->m_name = wfd.cFileName;	// ??
						pFile->m_wfd = wfd;

						AddChildTail(pFile);
					}
				}
			}
		}
		while (InternetFindNextFile(hFindFile, &wfd));

		InternetCloseHandle(hFindFile);
	}

//	DWORD lastError = GetLastError();
//	if (lastError) WinError(lastError);

	if (bCheckExisting)
	{
	// Traverse all items, and remove the files that no longer exist on disk
		UPOSITION pos = m_childList.GetHeadPosition();
		while (pos)
		{
			UPOSITION pos2 = pos;
			CSiteItem* pItem = (CSiteItem*)m_childList.GetNext(pos);
			if (!pItem->m_bFoundOnDisk)
			{
			//	if (*pActive == pItem) *pActive = NULL;

				//pItem->RemoveFromDatabase();

				pItem->m_parent->m_childList.RemoveAt(pos2);
				delete pItem;
			}
		}
	}
}
Exemple #7
0
int PreProc_FtpDownloadFiles( char *downloadURL, char *tempLocation, int deleteFiles )
{

	if ( IsURL( downloadURL ) && !IsStopped() )
	{
		char	*p;
		long	count=0, filenum;
		char	server[128], path[256], name[64], passwd[32];
#if DEF_WINDOWS
		WIN32_FIND_DATA  lpFindFileData;
		HINTERNET hFind, fs;

		char msg[256];

		ExtractUserFromURL(  downloadURL, server, name, passwd, path );
		DateFixFilename( path, 0 );

		OutDebugs( "Doing PreProcess Download %s...", path );

		fs = (void*)FtpServerOpen( server, name, passwd );

		if ( !fs )
		{
			FtpServerOpenError( server );
			return -1;
		}

		if ( fs )
		{
			long flags = INTERNET_FLAG_NO_CACHE_WRITE;
			char newpath[512];

			// *****************************************************************
			// To be more friendly with various FTP servers, we need to break
			// up the filename from the directory that it is contained in.
			// We can then change to the directory prior to fetching the file.
			// The issue here is that some FTP servers can not get a file that
			// has path information in it (ie: /directory1/dir2/file.dat)
			// *****************************************************************
			int iLen;
			for (iLen=mystrlen(path);iLen && path[iLen]!='/';--iLen)
				;
			if (!iLen)	// then there is no '/'
			{
				mystrcpy( newpath, path+1 );
			}
			else
			{
				path[iLen] = NULL;	// Set the '/' to a NULL so we have a path up to the name.
				if (!::FtpSetCurrentDirectory(fs,"/"))	// Set it to root just to be sure.
				{
					// we have a problem, however there is no real way to action this.
					// so lets just hope that the fetch will still work.
				}

				if (!::FtpSetCurrentDirectory(fs,path))
				{
					// again.
					// we have a problem, however there is no real way to action this.
					// so lets just hope that the fetch will still work.
					path[iLen] = '/';
				}

				mystrcpy( newpath, path+iLen+1 );
			}


			hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 );
			if ( !hFind ){
				unsigned long len = 512;
				FtpServerClose( fs );

				OutDebugs( "%s Not Found....Trying root level path instead...", newpath );
				fs = (void*)FtpServerOpen( server, name, passwd );
				if ( fs )
				{
					FtpGetCurrentDirectory( fs, newpath, &len );
					strcat( newpath, path );
					hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 );
				} else
					FtpServerOpenError( server );
			}

			if ( hFind )
				OutDebugs( "Ftp File Found %s size = %d", lpFindFileData.cFileName, lpFindFileData.nFileSizeLow );
			else {
				ErrorMsg( "Cannot open ftp file ...\n%s\nBecause %s", newpath, NetworkErr(NULL) );
				FtpServerClose( fs );
				return -1;
			}

			filenum = 0;

			while( hFind && !IsStopped() )
			{
				long ret;
				char ftpfilename[256], localfilename[256];

				if( hFind )
				{
					ftpfilename[0] = 0;
					if ( !strchr( lpFindFileData.cFileName , '/' ) ){
						// only if NEWPATH has a / in it copy it.
						
						if ( strchr( newpath , '/' ) ){
							mystrcpy( ftpfilename, newpath );
							p = strrchr( ftpfilename, '/');
							if ( p ) *p = 0;
						}
						strcat( ftpfilename, "/" );
						strcat( ftpfilename, lpFindFileData.cFileName );
					} else
						mystrcpy( ftpfilename, lpFindFileData.cFileName );

					// Figure out local file name
					if ( *tempLocation == 0 || GetFileAttributes( tempLocation ) != FILE_ATTRIBUTE_DIRECTORY )
					{
						sprintf( msg, "%%TEMP%%\\%s", FileFromPath( ftpfilename,NULL ) );
						ExpandEnvironmentStrings( msg, localfilename, 255 );
						StatusSetID(  IDS_STOREFILEINTEMP  );
						OutDebugs( "Using system temp location %s", localfilename );
					} else {
						PathFromFullPath( tempLocation, localfilename );
						if( strlen( localfilename ) )
						{
							strcat ( localfilename, "\\" );
							p = FileFromPath( ftpfilename,NULL );
							if ( !p ) p = "temp.log";
							strcat ( localfilename, p );
						} else
							mystrcpy( localfilename, "temp.log" );
						OutDebugs( "Using user temp location %s", localfilename );
					}

					OutDebugs( "Trying to download %d byte file '%s' into '%s' ...", lpFindFileData.nFileSizeLow, ftpfilename, localfilename );

					ret = FtpFileDownload( fs, downloadURL, localfilename, ftpfilename, lpFindFileData.nFileSizeLow );
					if ( ret > 0 )
					{
						if ( deleteFiles ){			// delete remote ftp file after downloading
							StatusSetID( IDS_DELETEFTP, ftpfilename );
							FtpDelFile( fs, ftpfilename );
						}
						AddFileToLogQ( localfilename, filenum++ );
					} else {
						OutDebugs( "error downloading (%d)", ret );
						ErrorMsg( "Cannot download file %s\n%s", NetworkErr(NULL) );
						hFind = NULL;
						FtpServerClose( fs );
						return -2;
					}
					//------------------------
				} //if( hFind )

				if ( hFind ) {
					if( InternetFindNextFile( hFind, &lpFindFileData ) == FALSE )
						hFind = NULL;
				}
			} //while
			FtpServerClose( fs );
		} 
#endif
	}
	return IsStopped();
}