1

我正在尝试使用 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 上运行)

4

0 回答 0