Closed Pfannaa closed 3 years ago
CreateFile should be used to obtain the handle to the subdirectory you want to query. (e.g. '\Temp') QueryDirectory should specify the filter within the directory.
Yeah i get the idea, although.. If you are using an SMB1FileStore, it doesn't let you pass in the handle. As seen as in my screenshot.
Which means, i always get the root directories info. Doesn't matter which path i pass in.
If i try to pass in the handle like this:
if (!_isSMBV2)
{
status = fileStore.CreateFile(out dirHandle, out fileStatus, @"\Temp", AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
if (status == NTStatus.STATUS_SUCCESS)
{
status = ((SMB1FileStore)fileStore).QueryDirectory(out fileListSMB1, dirHandle, "\\*", FileInformationClass.FileFullDirectoryInformation);
status = fileStore.CloseFile(dirHandle);
foreach (var file in fileListSMB1)
{
string fileName = ((SMBLibrary.FileFullDirectoryInformation)file).FileName.ToString();
ReturnableFileList.Add(fileName);
}
}
}
I always get a NotImplementedException at the QueryDirectory call
And now i know why :) -->
I guess i need to format the path in a different way (i tried "\temp" and various other constellations). Could you please provide the correct formatting ?
Sorry, for SMB1 QueryDirectory accepts the path relative to the share, for example:
status = ((SMB1FileStore)fileStore).QueryDirectory(out fileList2, "\\Trip\\*", FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO);
(When "Trip" is the name of the folder insider the share)
Thank you so much! Working like a charm.
hi @TalAloni , i want to access the file from my shared folder \Servever\ROOT\Useruploaded \2024\3\29\Data.pdf
IPAddress iPAddress = IPAddress.Parse(server);
// Connect to the SMB server
SMB2Client client = new SMB2Client();
bool isConnected = client.Connect(iPAddress, SMBTransportType.DirectTCPTransport);
// Connect to the share
NTStatus status1;
if (isConnected)
{
List
ISMBFileStore fileStore = client.TreeConnect("Root", out status);
if (status == NTStatus.STATUS_SUCCESS)
{
object directoryHandle;
FileStatus fileStatus;
status = fileStore.CreateFile(out directoryHandle, out fileStatus, @"\ Useruploaded \2024\3\29\Data.pdf", AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
status = fileStore.CreateFile(out directoryHandle, out fileStatus, "\\", AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
if (status == NTStatus.STATUS_SUCCESS)
{
List<FindInformation> fileList2;
status = ((SMB1FileStore)fileStore).QueryDirectory(out fileList2, "\\*", FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO);
//status=fileStore1.QueryDirectory(out fileList2, "\\*", FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO);
//status = fileStore.CloseFile(directoryHandle);
}
//object directoryHandle;
//FileStatus fileStatus;
status = fileStore.CreateFile(out directoryHandle, out fileStatus, String.Empty, 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;
List<QueryFileAllInfo> fileList2;
status = fileStore.QueryDirectory(out fileList, directoryHandle, "*", FileInformationClass.FileDirectoryInformation);
foreach (FileDirectoryInformation file in fileList)
{
Console.WriteLine($"Filename: {file.FileName}");
Console.WriteLine($"File Size: {file.AllocationSize / 1024}KB");
Console.WriteLine($"Created Date: {file.CreationTime.ToString("f")}");
Console.WriteLine($"Last Modified Date: {file.LastWriteTime.ToString("f")}");
Console.WriteLine();
Console.WriteLine();
}
//status=fileStore.GetFileInformation(out FileInformation result, directoryHandle, FileInformationClass.fileinfo);
status = fileStore.CloseFile(directoryHandle);
}
}
But am getting the Exception as STATUS_INVALID_PARAMETER Can you please help how can we access the file From subfolders of Shared Root Folder
@Shashichanti if you do not know which parameters should be sent (which often happens for first-timers), I suggest you use WireShark to monitor the values sent by Windows clients and imitate that. BTW - it's weird that you call CreateFile twice in sequence without checking if the first call succeeded and without using the handle of the correct call - that's surely a bug. I'm too busy to help everybody with their buggy code - please figure it out or hire someone to help you.
Hi @TalAloni
Older post for reference: https://github.com/TalAloni/SMBLibrary/issues/9#issuecomment-376871908_
My problem is, i always get the root directorys information. From what i've unterstood. I need to create a handle to the subfolder i want to access. This works fine with SMBv2, but i just don't get how i need to pass the argument in the CreateFile Method with my smb1 client. What confuses me though: I can't pass the handle into the CreateFile method..
My Code: