Skip to content

Commit

Permalink
Merge pull request #142 from FrendsPlatform/issue-39
Browse files Browse the repository at this point in the history
Frends.SFTP.UploadFiles - Added new result attribute
  • Loading branch information
ttossavainen authored May 17, 2023
2 parents e1d8f97 + 57a25a4 commit 4aa60cb
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 2 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.6.0] - 2023-05-16
### Added
- Added new result attribute TransferredDestinationFilePaths list consisting of the file paths of destination files.

## [2.5.5] - 2023-05-05
### Fixed
- Fixed Permission denied error when using mounted CIFS share by canonizing the destination path.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NUnit.Framework;
using System.IO;
using System;
using System.Linq;
using System.Threading;
using Frends.SFTP.UploadFiles.Definitions;

Expand All @@ -24,7 +25,9 @@ public void UploadFiles_TestUsingMacros()
var result = SFTP.UploadFiles(_source, destination, _connection, _options, _info, new CancellationToken());
Assert.IsTrue(result.Success);
var date = DateTime.Now;
Assert.IsTrue(Helpers.CheckFileExistsInDestination("/upload/Upload/SFTPUploadTestFile1" + date.ToString(@"yyyy-MM-dd") + ".txt"));
var file = "/upload/Upload/SFTPUploadTestFile1" + date.ToString(@"yyyy-MM-dd") + ".txt";
Assert.AreEqual(file, result.TransferredDestinationFilePaths.ToList().FirstOrDefault());
Assert.IsTrue(Helpers.CheckFileExistsInDestination(file));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
using Frends.SFTP.UploadFiles.Definitions;
Expand All @@ -18,6 +19,7 @@ public void UploadFiles_TestSimpleTransfer()
var result = SFTP.UploadFiles(_source, _destination, _connection, _options, _info, new CancellationToken());
Assert.IsTrue(result.Success);
Assert.AreEqual(1, result.SuccessfulTransferCount);
Assert.AreEqual(Path.Combine(_destination.Directory, _source.FileName).Replace("\\", "/"), result.TransferredDestinationFilePaths.ToList().FirstOrDefault());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class FileTransferResult

public IEnumerable<string> TransferredFilePaths { get; set; }

public IEnumerable<string> TransferredDestinationFilePaths { get; set; }

public IDictionary<string, string> OperationsLog { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ private static FileTransferResult FormFailedFileTransferResult(string userResult
TransferredFileNames = new List<string>(),
TransferErrors = new Dictionary<string, IList<string>>(),
TransferredFilePaths = new List<string>(),
TransferredDestinationFilePaths = new List<string>(),
OperationsLog = new Dictionary<string, string>()
};
}
Expand Down Expand Up @@ -496,6 +497,7 @@ private FileTransferResult FormResultFromSingleTransferResults(List<SingleFileTr
TransferredFileNames = transferredFileResults.Select(r => r.TransferredFile ?? "--unknown--").ToList(),
TransferErrors = transferErrors,
TransferredFilePaths = transferredFileResults.Select(r => r.TransferredFilePath ?? "--unknown--").ToList(),
TransferredDestinationFilePaths = transferredFileResults.Select(r => r.TransferredDestinationFilePath ?? "--unknown--").ToList(),
OperationsLog = new Dictionary<string, string>()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public class Result
/// </example>
public IEnumerable<string> TransferredFilePaths { get; private set; }

/// <summary>
/// List of destaintion file paths of the transferred files.
/// </summary>
/// <example>
/// <code>
/// [
/// "upload/Upload/test.txt",
/// "upload/Upload/test2.txt"
/// ]
/// </code>
/// </example>
public IEnumerable<string> TransferredDestinationFilePaths { get; private set; }

/// <summary>
/// Operations logs for the transfer.
/// </summary>
Expand All @@ -107,6 +120,7 @@ internal Result(FileTransferResult result)
TransferredFileNames = result.TransferredFileNames;
TransferErrors = result.TransferErrors;
TransferredFilePaths = result.TransferredFilePaths;
TransferredDestinationFilePaths = result.TransferredDestinationFilePaths;
OperationsLog = result.OperationsLog;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ internal SingleFileTransferResult TransferSingleFile()
if (!string.IsNullOrEmpty(destinationFileRestoreMessage))
HandleTransferError(ex, destinationFileRestoreMessage);
}
_result.TransferredDestinationFilePath = DestinationFileWithMacrosExpanded;
return _result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal class SingleFileTransferResult

internal string TransferredFilePath { get; set; }

internal string TransferredDestinationFilePath { get; set; }

internal SingleFileTransferResult()
{
ErrorMessages = new List<string>();
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.5.5</Version>
<Version>2.6.0</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down

0 comments on commit 4aa60cb

Please sign in to comment.