新建ftp站点

#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;  
}  

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值