0

So I need to acces a subfolder in Sharedrive with the SMBLibrary. I was expecting a list of folders of the subfolder but I always get a 0 count.

SMB2Client client = new SMB2Client();

bool isConnected = client.Connect("myServername", SMBTransportType.DirectTCPTransport);
if (isConnected)
{
    NTStatus status = client.Login(String.Empty, "user", "password");
    if (status == NTStatus.STATUS_SUCCESS)
    {
        List<string> shares = client.ListShares(out status);

        ISMBFileStore fileStore = client.TreeConnect("ShareName", out status);

        object directoryHandle;
        FileStatus fileStatus;
        string folder = @"ShareName/SUBFOLDER";

        status = fileStore.CreateFile(out directoryHandle, out fileStatus, folder, AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);

         if(status == NTStatus.STATUS_SUCCESS)
         {
              List<QueryDirectoryFileInformation> fileList;
              status = fileStore.QueryDirectory(out fileList, directoryHandle, @"*", FileInformationClass.FileDirectoryInformation);
              status = fileStore.CloseFile(directoryHandle);
         }
         status = fileStore.Disconnect();
         client.Logoff();
      }
      client.Disconnect();
}
AaronH2001
  • 48
  • 5
  • Why are you using `SMB2Client` instead of just using the shared folder path, eg `\\someserver\sharedfolder\path-to-file.zip` ? Why specify an explicit hard-code password instead of letting Windows handle authentication the way it does when you use Windows Explorer? – Panagiotis Kanavos Dec 21 '22 at 14:01

1 Answers1

0

after you perform TreeConnect to connect to a share, you shouldn't specify the share name when operating on that share. In your example, you call CreateFile and including the ShareName which is incorrect.

Tal Aloni
  • 1,429
  • 14
  • 14