Skip to content

Commit

Permalink
Merge pull request #6 from andreaskueffel/development fix #5
Browse files Browse the repository at this point in the history
fix creation of subfolders if they are not existent fix #5
  • Loading branch information
andreaskueffel authored Jul 20, 2023
2 parents af8503c + 5ed4a0f commit b8729cd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions SyncProviders/SmbLibProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ public void WriteFile(string localFilePath, string remoteFilePath)
FileStream localFileStream = new FileStream(localFilePath, FileMode.Open, FileAccess.Read);
object fileHandle;
FileStatus fileStatus;
//Create folders recursive

var paths = remoteFilePath.Trim('/', '\\').Split('/', '\\');
if (paths.Length > 1)
{
string createpath = "";
for (int i = 0; i < paths.Length - 1; i++)
{
createpath = Path.Combine(createpath, paths[i]);
status = fileStore.CreateFile(out fileHandle, out fileStatus, createpath, AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_OPEN_IF, CreateOptions.FILE_DIRECTORY_FILE, null);
if (status == NTStatus.STATUS_SUCCESS)
{
status = fileStore.CloseFile(fileHandle);
}
}
}

status = fileStore.CreateFile(out fileHandle, out fileStatus, remoteFilePath.Trim('/','\\'), AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_SUPERSEDE, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
if (status == NTStatus.STATUS_SUCCESS)
{
Expand Down

0 comments on commit b8729cd

Please sign in to comment.