Skip to content

Commit

Permalink
Merge pull request #166 from FrendsPlatform/issue-165
Browse files Browse the repository at this point in the history
SFTP.UploadFiles - Added new parameter AssumeFileExistence
  • Loading branch information
Svenskapojkarna authored Oct 20, 2023
2 parents 4a45a17 + 7c2b268 commit 60db2e7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Frends.SFTP.UploadFiles/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [2.8.0] - 2023-10-18
### Added
- [Breaking] New feature: Added parameter AssumeFileExistence which will when enabled, skip checking if destination file esists and overwrites any existing files automatically.

## [2.7.2] - 2023-09-20
### Fixed
- Fixed issue with empty destination directory by adding forward slash to the parameter if it's empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private static string GetUserResultMessage(IList<SingleFileTransferResult> resul
userResultMessage = MessageJoin(userResultMessage,
$"{errorMessages.Count} Errors: {string.Join(",\n", errorMessages)}.");

var transferredFiles = results.Where(x => x.Success).Select(x => x.TransferredFile).ToList();
var transferredFiles = results.Where(x => x.Success && !x.ActionSkipped).Select(x => x.TransferredFile).ToList();
if (transferredFiles.Any())
userResultMessage = MessageJoin(userResultMessage,
$"{transferredFiles.Count} files transferred: {string.Join(",\n", transferredFiles)}.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public class Options
/// <example>true</example>
[DefaultValue(true)]
public bool OperationLog { get; set; }

/// <summary>
/// If enabled, the Task will assume that the destination file exists and skip the checking of the destination file.
/// This option will automatically overwrite existing destination file with the same name as the transferred one.
/// This can help transfers with server when user has limited permissions to the destination directory e.g. no permission to do lstat command.
/// </summary>
/// <example>false</example>
[DefaultValue(false)]
public bool AssumeFileExistence { get; set; }
}


Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ internal SingleFileTransferResult TransferSingleFile()

ExecuteSourceOperationMoveOrRename();

if (DestinationFileExists(DestinationFileWithMacrosExpanded))
if (BatchContext.Options.AssumeFileExistence)
{
PutDestinationFile(removeExisting: true);
}
else if (DestinationFileExists(DestinationFileWithMacrosExpanded))
{
DestinationFile = new FileItem(Client.Get(DestinationFileWithMacrosExpanded));
switch (BatchContext.Destination.Action)
Expand All @@ -73,7 +77,10 @@ internal SingleFileTransferResult TransferSingleFile()
throw new DestinationFileExistsException(Path.GetFileName(DestinationFileWithMacrosExpanded));
}
}
else PutDestinationFile();
else
{
PutDestinationFile();
}

if (BatchContext.Options.PreserveLastModified) RestoreModified();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssemblyName>Frends.SFTP.UploadFiles</AssemblyName>
<RootNamespace>Frends.SFTP.UploadFiles</RootNamespace>

<Version>2.7.2</Version>
<Version>2.8.0</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down

0 comments on commit 60db2e7

Please sign in to comment.