#include <windows.h>
#include <Iads.h>
#include <comdef.h>
#include <tchar.h>
#include <stdio.h>
#include <Adshlp.h>
#pragma comment(lib,"ActiveDS")
#pragma comment(lib,"adsiid")
BOOL CreateFtpSite(LPCTSTR bindaddress,LPCTSTR domain,LPCTSTR DiskPath,LPCTSTR LogPath);
void main()
{
CoInitialize(NULL);
if(TRUE==CreateFtpSite(_T("192.168.2.148:8021"),_T("lgftp"),_T("d:\\work")))
printf("create site ok\n");
else
printf("create site failed\n");
CoUninitialize();
}
BOOL CreateFtpSite(LPCTSTR bindaddress,LPCTSTR domain,LPCTSTR pathname,LPCTSTR LogPath)
{
if(bindaddress==NULL||NULL==domain||NULL==pathname)
return FALSE;
IADsContainer *pCont=NULL;
IADs* pAds=NULL;
IADs* pVrAds=NULL;
IADsServiceOperations *pSrvOp=NULL;
IDispatch *pDisp = NULL;
IDispatch *pVrDisp = NULL;
_bstr_t WNumer="235";
_bstr_t newBindings=_bstr_t(bindaddress)+":"+domain;
HRESULT hr;
if(ADsGetObject(L"IIS://localhost/MSFTPSVC",IID_IADsContainer,(void**)&pCont)==S_OK)
{
if(pCont->Create(L"IIsFtpServer",WNumer,&pDisp)==S_OK)
{
hr=pDisp->QueryInterface(IID_IADs, (void**)&pAds);
hr=pDisp->QueryInterface(IID_IADsServiceOperations, (void**)&pSrvOp);
pAds->Put(L"ServerSize",_variant_t(long(1)));
pAds->Put(L"ServerComment",_variant_t(_bstr_t("masterz")));
pAds->Put(L"ServerBindings",_variant_t(newBindings));
pAds->Put(L"AnonymousPasswordSync",_variant_t(true));
pAds->Put(L"AllowAnonymous",_variant_t(false));
pAds-> Put(L"LogFileLocaltimeRollover",_variant_t(true));
pAds-> Put(L"LogFileDirectory",_variant_t(LogPath));
pAds->SetInfo();
hr=pCont->GetObject(L"IIsFtpServer",(WNumer),&pDisp);
if(pDisp->QueryInterface(IID_IADsContainer,(void**)&pCont)==S_OK)
{
if(pCont->Create(L"IIsFtpVirtualDir",L"Root",&pVrDisp)==S_OK)
{
hr=pVrDisp->QueryInterface(IID_IADs, (void**)&pVrAds);
pVrAds->Put(L"AccessRead",_variant_t(true));
pVrAds->Put(L"AccessScript",_variant_t(true));
pVrAds->Put(L"Path",_variant_t(pathname));
pVrAds->SetInfo();
pVrAds->Release();
pAds->Release();
pCont->Release();
}
hr=pSrvOp->Start();
hr=pSrvOp->Release();
}
}
}
return true;
}