我正在尝试使用libsmbclient库观看使用Windows 7 / XP SMB共享的远程主机的fs结构。代码类似于:
bool open(QList<DirType> &resList){
SMBCFILE* dh = smbc_getFunctionOpendir(ctx)(ctx,rootpath.toLocal8Bit());
if (dh==NULL) return false;
smbc_dirent *res;
bool isitZeroLevel = false;
while (res=smbc_getFunctionReaddir(ctx)(ctx,dh)){
if (res->smbc_type==SMBC_FILE_SHARE) isitZeroLevel=true;
struct stat aboutres;
smbc_getFunctionStat(ctx)(ctx,(rootpath+"/"+smb_name).toLocal8Bit(),
&aboutres);
DirType d(res->smbc_type,res->name,aboutres.st_mtim.tv_sec);
resList.push_back(d);
}
smbc_getFunctionClosedir(ctx)(ctx,dh);
if(isitZeroLevel){
smbc_setOptionOneSharePerServer(ctx,1);
close();
}
return true;
}
为服务器上的每个目录递归调用此代码,并且在我的Samba服务器上正常工作。但Windows在某些方面拒绝连接。我认为Windows有一些连接限制,而smbclient使它们太多了。 (使用samba-3.5.15在linux-3.4.9上运行)