Skip to content

Commit

Permalink
Allow config parameter "LocalFileShareOption" to be configured. Defau…
Browse files Browse the repository at this point in the history
…lt is of course FileShare.Read.
  • Loading branch information
FanDjango committed May 12, 2023
1 parent 6120592 commit 2d0115a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions FluentFTP/Model/FtpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Authentication;
Expand Down Expand Up @@ -427,6 +428,12 @@ public TimeSpan GetLocalTimeOffset() {
/// </summary>
public int LocalFileBufferSize { get; set; } = 4096;

/// <summary>
/// Gets or sets the FileShare setting to be used when opening a FileReadStream for uploading to the server,
/// which needs to be set to FileShare.ReadWrite in special cases to avoid denied access.
/// </summary>
public FileShare LocalFileShareOption { get; set; } = FileShare.Read;

protected int _retryAttempts = 3;

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion FluentFTP/Streams/FtpFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public static Stream GetFileReadStream(BaseFtpClient client, string localPath, b

// normal slow mode, return a FileStream
var bufferSize = client != null ? client.Config.LocalFileBufferSize : 4096;
return new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, isAsync);
var shareOption = client != null ? client.Config.LocalFileShareOption : FileShare.Read;
return new FileStream(localPath, FileMode.Open, FileAccess.Read, shareOption, bufferSize, isAsync);
}

/// <summary>
Expand Down

0 comments on commit 2d0115a

Please sign in to comment.