Chinaunix首页 | 论坛 | 博客
  • 博客访问: 341588
  • 博文数量: 89
  • 博客积分: 5152
  • 博客等级: 大校
  • 技术积分: 1155
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-25 15:12
文章分类

全部博文(89)

文章存档

2012年(1)

2011年(5)

2010年(14)

2009年(69)

我的朋友

分类: C/C++

2009-12-30 13:21:01

以ftp为例,使用ABO访问ftp

参考文档:





typedef pair<CString, CString> StringPair;
typedef CList<StringPair, StringPair&> StrPairList;


BOOL getFtpEntry(StrPairList& entryList)
{
    CoInitalize(NULL)
    CComPtr<IMSAdminBase> pIMetaDB;
    HRESULT hRes = CoCreateInstance
    (
         CLSID_MSAdminBase
        , NULL
        , CLSCTX_ALL
        , IID_IMSAdminBase
        , (void **)&pIMetaDB
    );
    if ( hRes < 0 ) {
        return FALSE;
    }

    METADATA_HANDLE metaHandel;
    hRes = pIMetaDB->OpenKey
        (
     METADATA_MASTER_ROOT_HANDLE
     , (LPWSTR)(L"/LM/MSFTPSVC")
     , METADATA_PERMISSION_READ
     , e_MaxTime
     , &metaHandel
        );
     if ( hRes < 0 ) {
        return FALSE;
    }

    WCHAR site[METADATA_MAX_NAME_LEN], siteName[METADATA_MAX_NAME_LEN];
    memset(&site, 0x0, sizeof(site));
    memset(&siteName, 0x0, sizeof(siteName));
    DWORD num = 0;
   

     for (;;) {
        hRes = pIMetaDB->EnumKeys(metaHandel, L"/", site, num);
        if ( hRes < 0 ) {
            break;
        }  
        num++;
        if (_wcsicmp(site, L"1") != 0) {
                 continue;
        }
        memset(&siteName, 0x0, sizeof(siteName));
        wcscpy(siteName, L"/");
        wcscat(siteName, site);
        wcscat(siteName, L"/ROOT");

        DWORD len = 0;
        WCHAR data[METADATA_MAX_NAME_LEN];
        memset(&data, 0x0, sizeof(data));

        METADATA_RECORD record;
        memset(&record, 0x0, sizeof(record));
        record.dwMDIdentifier = MD_VR_PATH;
        record.dwMDAttributes = METADATA_INHERIT;
        record.dwMDUserType = IIS_MD_UT_FILE;
        record.dwMDDataType = STRING_METADATA;
        record.dwMDDataTag = 0;
        record.dwMDDataLen = sizeof(data);
        record.pbMDData = (PBYTE)data;
    
        hRes = pIMetaDB->GetData(metaHandel, siteName, &record, &len);
        if (hRes < 0) {
            pIMetaDB->CloseKey(metaHandel);
            return FALSE;
        }

        CString path(data);
        StringPair pair(_T("/"), path);
        entryList.insert(pair);
        browseVDir(pIMetaDB, metaHandel, siteName, NULL, entryList);
    }

    pIMetaDB->CloseKey(metaHandel);

    UnCoInitialize();
    return TRUE;
}

static BOOL browseVDir(
    IMSAdminBase* pIMetaDB,
    METADATA_HANDLE metaHandel,
    const WCHAR* subkey,
    const TCHAR* dir,
    StrPairList& flist
)
{
    ASSERT(pIMetaDB != NULL);

    DWORD index = 0;
    WCHAR subdir[METADATA_MAX_NAME_LEN], fullPath[METADATA_MAX_NAME_LEN];
    memset(&subdir, 0x0, sizeof(subdir));
    memset(&fullPath, 0x0, sizeof(fullPath));

    for (;;) {
        HRESULT hRes = pIMetaDB->EnumKeys(metaHandel, subkey, subdir, index);
        if ( hRes < 0) {
            break;
        }
 
        memset(&fullPath, 0x0, sizeof(fullPath));
        wcscpy(fullPath, subkey);
        wcscat(fullPath, L"/");
        wcscat(fullPath, subdir);

        DWORD len = 0;
        WCHAR data[METADATA_MAX_NAME_LEN];
        memset(&data, 0x0, sizeof(data));

        METADATA_RECORD record;
        memset(&record, 0x0, sizeof(record));
        record.dwMDIdentifier = MD_VR_PATH;
        record.dwMDAttributes = METADATA_INHERIT;
        record.dwMDUserType = IIS_MD_UT_FILE;
        record.dwMDDataType = STRING_METADATA;
        record.dwMDDataTag = 0;
        record.dwMDDataLen = sizeof(data);
        record.pbMDData = (PBYTE)data;
            
        hRes = pIMetaDB->GetData(metaHandel, fullPath, &record, &len);
        if ( hRes < 0 ) {
            return FALSE;
        }
        CString path(data);
        CString fl(subdir);
        fl = CString(dir) + _T("/") + fl;
        StringPair pair(fl, path);
        flist.insert(pair);

        browseVDir(pIMetaDB, metaHandel, fullPath, fl, flist);
        index++;
    }

    return TRUE;
}


阅读(856) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~