This commit is contained in:
Zeeshaun
2026-03-24 15:28:37 -05:00
parent 9cc87337b8
commit 73d62efb39
58 changed files with 2952 additions and 0 deletions
@@ -0,0 +1,55 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.11.2</Version>
<PackageVersion>2.11.3</PackageVersion>
<Description>
1.0.0 - Initial Creation
1.1.0 - Added ProtocolType and removed WinSCP
2.0.0 - Adding PortNumber that is required but defaulted to 22
2.1.0 - Add SftpResponse
2.2.0 - Update Queue and ApiResponse Libraries
2.3.0 - Add SftpDynamicFileRequest
2.4.0 - Added SftpUploadfileRequest, SftpDownLoadFileRequest, QueueRequest(from api models), SshFtpRequest, and FtpRequestResponse
2.5.0 - Upgrade ApiResponse and FileOperations Libraries
2.6.0 - New ApiResponse nuget to use ExchangeName.
2.7.0 - Update to SftpUploadFileRequest
2.8.0 - Update to SftpDownloadFileRequest. Adds should remove true or false toggle
2.9.0 - Update upload and download. Add SucceeddOnEmpty toggle. Alteratiosn to FileOperationsService.
2.9.1 - Added DynamicNameSetting for local and remote file paths
2.10.0 - Fix Download/Uploads local/remote paths to append slashes on final.
2.11.0 - Add ResumeSupport toggle.
2.11.1 - Add SshKeyFilePath to SessionInformation
2.11.2 - Add ResumeSupport toggle to download request
2.11.3 - Upgraded FileOperations package version
</Description>
<PackageReleaseNotes>
1.0.0 - Initial Creation
1.1.0 - Added ProtocolType and removed WinSCP
2.0.0 - Adding PortNumber that is required but defaulted to 22
2.1.0 - Add SftpResponse
2.2.0 - Update Queue and ApiResponse Libraries
2.3.0 - Add SftpDynamicFileRequest
2.4.0 - Added SftpUploadfileRequest, SftpDownLoadFileRequest, QueueRequest(from api models), SshFtpRequest, and FtpRequestResponse
2.5.0 - Upgrade ApiResponse and FileOperations Libraries
2.6.0 - New ApiResponse nuget to use ExchangeName.
2.7.0 - Update to SftpUploadFileRequest
2.8.0 - Update to SftpDownloadFileRequest. Adds should remove true or false toggle
2.9.0 - Update upload and download. Add SucceeddOnEmpty toggle. Alteratiosn to FileOperationsService.
2.9.1 - Added DynamicNameSetting for local and remote file paths
2.10.0 - Fix Download/Uploads local/remote paths to append slashes on final.
2.11.0 - Add ResumeSupport toggle.
2.11.1 - Add SshKeyFilePath to SessionInformation
2.11.2 - Add ResumeSupport toggle to download request
2.11.3 - Upgraded FileOperations package version
</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>LCU Internal FTP Library</Title>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LCU.Library.Internal.ApiResponse.Models" Version="3.3.0" />
<PackageReference Include="LCU.Library.Internal.FileOperationsModels" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.2.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
namespace LCU.Api.Internal.FTPLib.Models.Enums
{
public enum FtpType
{
Other,
WinScpSftpDownload,
WinScpSftpUpload,
SshFtp
}
}
@@ -0,0 +1,21 @@
using LCU.Library.Internal.ApiResponse.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace LCU.Api.Internal.FTPLib.Models
{
public class FtpRequestResponse
{
public FtpRequestResponse()
{
MessageStack = new List<string>();
IsSuccessful = true;
ReturnResponse = null;
}
public List<string> MessageStack { get; set; }
public bool IsSuccessful { get; set; }
public ReturnResponse ReturnResponse { get; set; }
}
}
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace LCU.Api.Internal.FTPLib.Models
{
public class ListDirectoryRequest
{
public SessionInformation SessionInformation { get; set; }
[Required]
public string RemotePath { get; set; }
}
}
@@ -0,0 +1,7 @@
namespace LCU.Api.Internal.FTPLib.Models
{
public enum ProtocolType
{
Sftp
}
}
@@ -0,0 +1,18 @@
using LCU.Api.Internal.FTPLib.Models.Enums;
namespace LCU.Api.Internal.FTPLib.Models
{
public class QueueRequest
{
public QueueRequest()
{
Guid = System.Guid.NewGuid().ToString();
Attempts = 0;
}
public string Guid { get; }
public string Request { get; set; }
public int? Attempts { get; set; }
public FtpType FtpType { get; set; }
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace LCU.Api.Internal.FTPLib.Models
{
public class SessionInformation
{
[Required]
public ProtocolType Protocol { get; set; }
[Required]
public string HostName { get; set; }
[Required, Range(1, 999999)]
public int PortNumber { get; set; } = 22;
[Required]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
[Required]
public string SshHostKeyFingerprint { get; set; }
public string SshKeyFilePath { get; set; }
}
}
@@ -0,0 +1,60 @@
using LCU.Library.Internal.ApiResponse.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.FileOperationsModels.Shared;
using System.ComponentModel;
namespace LCU.Api.Internal.FTPLib.Models
{
public class SftpDownloadFileRequest : ReturnResponse
{
[Required]
public SessionInformation SessionInformation { get; set; }
[Required]
public string RemoteFilePath { get; set; }
[Required]
public string RemoteFileName { get; set; }
[Required]
public string LocalFilePath { get; set; }
[DefaultValue(false)]
public bool ShouldRemove { get; set; }
[DefaultValue(false)]
public bool SucceedOnEmpty { get; set; }
public DynamicNameSetting DynamicNameSetting { get; set; }
[DefaultValue(true)]
public bool ResumeSupportStateOn { get; set; } = true;
[NotMapped]
public string FinalRemoteFileName
{
get
{
return DynamicNameBuilder.BuildDynamicName(RemoteFileName, DynamicNameSetting);
}
}
public DynamicNameSetting DynamicRemotePathSetting { get; set; }
public DynamicNameSetting DynamicLocalPathSetting { get; set; }
[NotMapped]
public string FinalRemoteFilePath
{
get
{
var remoteFilePath = RemoteFilePath.EndsWith("/") ? RemoteFilePath : $"{RemoteFilePath}/";
return DynamicNameBuilder.BuildDynamicName(remoteFilePath, DynamicRemotePathSetting);
}
}
[NotMapped]
public string FinalLocalFilePath
{
get
{
var localFilePath = LocalFilePath.EndsWith("\\") ? LocalFilePath : $"{LocalFilePath}\\";
return DynamicNameBuilder.BuildDynamicName(localFilePath, DynamicLocalPathSetting);
}
}
}
}
@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations.Schema;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.FileOperationsModels.Shared;
namespace LCU.Api.Internal.FTPLib.Models
{
public class SftpDynamicFileRequest : SftpRequest
{
[NotMapped]
public string FinalLocalFilePath
{
get
{
return $"{LocalFilePath}\\{DynamicNameBuilder.BuildDynamicName(LocalFileName, DynamicNameSetting)}";
}
}
public string LocalFileName { get; set; }
public DynamicNameSetting DynamicNameSetting { get; set; }
}
}
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using LCU.Library.Internal.ApiResponse.Models;
using System.ComponentModel.DataAnnotations;
using System;
namespace LCU.Api.Internal.FTPLib.Models
{
[Obsolete("Please use SftpDownloadFileRequest and SshFtpRequst Models")]
public class SftpRequest : ReturnResponse, IValidatableObject
{
[Required]
public ProtocolType Protocol { get; set; }
[Required]
public string HostName { get; set; }
[Required, Range(1, 999999)]
public int PortNumber { get; set; } = 22;
[Required]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
[Required]
public string SshHostKeyFingerprint { get; set; }
public string LocalFilePath { get; set; }
[Required]
public string RemoteFilePath { get; set; }
public byte[] LocalFileData { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (string.IsNullOrWhiteSpace(LocalFilePath) && LocalFileData == null)
{
yield return new ValidationResult(
$"One of LocalFilePath or LocalFileData bytes are required.",
new[] {nameof(LocalFileData), nameof(LocalFilePath)});
}
}
}
}
@@ -0,0 +1,11 @@
namespace LCU.Api.Internal.FTPLib.Models
{
// This should really throw on BadRequest and Error but I'm sticking to the original code intention for now.
public enum SftpResponse
{
BadRequest,
Success,
FailNoRetry,
FailWillRetry
}
}
@@ -0,0 +1,62 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using LCU.Library.Internal.ApiResponse.Models;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.FileOperationsModels.Shared;
using System.ComponentModel;
namespace LCU.Api.Internal.FTPLib.Models
{
public class SftpUploadFileRequest : ReturnResponse
{
[Required]
public SessionInformation SessionInformation { get; set; }
[Required]
public string LocalFilePath { get; set; }
[Required]
public string LocalFileName { get; set; }
[Required]
public string RemoteFilePath { get; set; }
public DynamicNameSetting DynamicNameSetting { get; set; }
[DefaultValue(false)]
public bool SucceedOnEmpty { get; set; } = false;
[DefaultValue(true)]
public bool ResumeSupportStateOn { get; set; } = true;
[NotMapped]
public string FinalLocalFileName
{
get
{
if (string.IsNullOrWhiteSpace(LocalFileName))
{
return LocalFileName;
}
return DynamicNameBuilder.BuildDynamicName(LocalFileName, DynamicNameSetting);
}
}
public DynamicNameSetting DynamicRemotePathSetting { get; set; }
public DynamicNameSetting DynamicLocalPathSetting { get; set; }
[NotMapped]
public string FinalRemoteFilePath
{
get
{
var remoteFilePath = RemoteFilePath.EndsWith("/") ? RemoteFilePath : $"{RemoteFilePath}/";
return DynamicNameBuilder.BuildDynamicName(remoteFilePath, DynamicRemotePathSetting);
}
}
[NotMapped]
public string FinalLocalFilePath
{
get
{
var localFilePath = LocalFilePath.EndsWith("\\") ? LocalFilePath : $"{LocalFilePath}\\";
return DynamicNameBuilder.BuildDynamicName(localFilePath, DynamicLocalPathSetting);
}
}
}
}
@@ -0,0 +1,22 @@
using LCU.Library.Internal.ApiResponse.Models;
using System.ComponentModel.DataAnnotations;
namespace LCU.Api.Internal.FTPLib.Models
{
public class SshFtpRequest : ReturnResponse
{
[Required]
public ProtocolType Protocol { get; set; }
[Required]
public string HostName { get; set; }
[Required, Range(1, 999999)]
public int PortNumber { get; set; } = 22;
[Required]
public string UserName { get; set; }
[Required]
public string Password { get; set; }
[Required]
public string RemoteFilePath { get; set; }
public byte[] LocalFileData { get; set; }
}
}