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,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; }
}
}