EquipmentList.OrderBy

This commit is contained in:
2025-03-05 11:07:18 +09:00
parent fb46e2b17a
commit f92e560e87
6 changed files with 168 additions and 61 deletions

View File

@@ -14,102 +14,163 @@ namespace JWH.NETWORK
public static void Initialize(string host, string userId, string password, int port = 990)
{
_host = host;
_userId = userId;
_password = password;
_port = port;
_ftpClient = new FluentFTP.FtpClient(_host, _port, new NetworkCredential(_userId, _password))
try
{
//EncryptionMode = FtpEncryptionMode.Explicit,
EncryptionMode = FtpEncryptionMode.Implicit,
SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
ConnectTimeout = 500 // 타임아웃 설정 (0.5초)
};
_ftpClient.ValidateCertificate += (control, args) => args.Accept = true; // 인증서 검증 비활성화 (운영 확인 필요!)
_host = host;
_userId = userId;
_password = password;
_port = port;
_ftpClient = new FluentFTP.FtpClient(_host, _port, new NetworkCredential(_userId, _password))
{
//EncryptionMode = FtpEncryptionMode.Explicit,
EncryptionMode = FtpEncryptionMode.Implicit,
SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
ConnectTimeout = 500 // 타임아웃 설정 (0.5초)
};
_ftpClient.ValidateCertificate += (control, args) => args.Accept = true; // 인증서 검증 비활성화 (운영 확인 필요!)
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
public static void Connect()
{
if (_ftpClient == null)
try
{
throw new InvalidOperationException("FTPS client is not initialized. Call Initialize() first.");
}
if (_ftpClient == null)
throw new InvalidOperationException("FTPS client is not initialized. Call Initialize() first.");
if (!_ftpClient.IsConnected)
if (!_ftpClient.IsConnected)
_ftpClient.Connect();
}
catch (Exception ex)
{
throw ex;
}
finally
{
_ftpClient.Connect();
}
}
public static void Disconnect()
{
if (_ftpClient != null && _ftpClient.IsConnected)
try
{
if (_ftpClient != null && _ftpClient.IsConnected)
_ftpClient.Disconnect();
}
catch (Exception ex)
{
throw ex;
}
finally
{
_ftpClient.Disconnect();
}
}
public static bool IsFileExists(string path)
{
Connect();
return _ftpClient.FileExists(path);
try
{
Connect();
return _ftpClient.FileExists(path);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Disconnect();
}
}
public static bool IsDirExists(string path)
{
Connect();
return _ftpClient.DirectoryExists(path);
try
{
Connect();
return _ftpClient.DirectoryExists(path);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Disconnect();
}
}
public static FtpListItem[] GetFtpsList(string path)
{
Connect();
return _ftpClient.GetListing(path);
try
{
Connect();
return _ftpClient.GetListing(path);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Disconnect();
}
}
public static object GetObjectInfo(string filePath)
{
Connect();
return _ftpClient.GetObjectInfo(filePath);
try
{
Connect();
return _ftpClient.GetObjectInfo(filePath);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Disconnect();
}
}
public static FtpListItem GetFileInfo(string remoteFilePath)
{
try
{
FtpsClient.Connect();
Connect();
if (!_ftpClient.IsConnected)
{
Console.WriteLine("FTPS 서버에 연결되지 않았습니다.");
return null;
}
throw new InvalidOperationException("FTPS 서버에 연결되지 않았습니다.");
// Passive Mode 설정 (필요한 경우)
// _ftpClient.SetPassiveMode(true);
// _ftpClient.SetPassiveMode(true);
if (!FtpsClient.IsFileExists(remoteFilePath))
{
Console.WriteLine("파일이 존재하지 않습니다.");
return null;
}
throw new InvalidOperationException("파일이 존재하지 않습니다.");
var fileInfo = FtpsClient.GetObjectInfo(remoteFilePath) ;
var fileInfo = FtpsClient.GetObjectInfo(remoteFilePath);
if (fileInfo == null)
{
Console.WriteLine("파일 정보를 가져오는 데 실패했습니다.");
}
throw new InvalidOperationException("파일 정보를 가져오는 데 실패했습니다.");
return (FtpListItem)fileInfo;
}
catch (Exception ex)
{
Console.WriteLine($"파일 정보 조회 오류: {ex.Message}");
return null;
throw ex;
}
finally
{
FtpsClient.Disconnect();
Disconnect();
}
}
@@ -123,8 +184,11 @@ namespace JWH.NETWORK
}
catch (Exception ex)
{
Console.WriteLine($"Download error: {ex.Message}");
return false;
throw ex;
}
finally
{
Disconnect();
}
}
@@ -138,8 +202,11 @@ namespace JWH.NETWORK
}
catch (Exception ex)
{
Console.WriteLine($"Upload error: {ex.Message}");
return false;
throw ex;
}
finally
{
Disconnect();
}
}
}

View File

@@ -50,8 +50,19 @@ namespace JWH.NETWORK
public static bool IsFileExists(string path)
{
Connect();
return _sftpClient.Exists(path);
try
{
Connect();
return _sftpClient.Exists(path);
}
catch
{
return false;
}
finally
{
Disconnect();
}
}
public static Renci.SshNet.Sftp.SftpFileAttributes GetFileInfo(string remoteFilePath)
@@ -74,12 +85,27 @@ namespace JWH.NETWORK
Console.WriteLine($"파일 정보 조회 오류: {ex.Message}");
return null;
}
finally
{
Disconnect();
}
}
public static object GetSftpList(string path)
{
Connect();
return _sftpClient.ListDirectory(path);
try
{
Connect();
return _sftpClient.ListDirectory(path);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Disconnect();
}
}
public static bool DownloadSftpFile(string remotePath, string localPath)
@@ -98,6 +124,10 @@ namespace JWH.NETWORK
Console.WriteLine($"Download error: {ex.Message}");
return false;
}
finally
{
Disconnect();
}
}
public static bool UploadSftpFile(string localPath, string remotePath)
@@ -116,6 +146,10 @@ namespace JWH.NETWORK
Console.WriteLine($"Upload error: {ex.Message}");
return false;
}
finally
{
Disconnect();
}
}
}
}