EnterpriseDT.Net.Ftp
를 이용한 FTP 연결 코드
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using EnterpriseDT.Net.Ftp;
public class FtpOperationExample
{
public static void Main(string[] args)
{
try
{
var srcDirPath = @"C:\Users\seungha.lee\Desktop\minio_src";
var dstDirPath = "/ftpcopy";
var localDstDirPath = "/ftpcopy";
var ftpUsername = "mlsftp";
var ftpPassword = "mlsftp1234";
var srcFullPath = Directory.GetFiles(srcDirPath);
var dstFullPath = new List<string>();
foreach (var file in srcFullPath)
{
var fileName = Path.GetFileName(file);
//var tmpPath = dstDirPath + "/" + fileName;
var tmpPath = localDstDirPath + "/" + fileName;
dstFullPath.Add(tmpPath);
}
FTPConnection ftp = new FTPConnection();
//ftp.ServerAddress = "192.168.170.25";
ftp.ServerAddress = "127.0.0.1";
ftp.ServerPort = 21;
ftp.UserName = ftpUsername;
ftp.Password = ftpPassword;
ftp.Connect();
//await Task.Run(() => ftp.Connect());
if (!ftp.IsConnected)
{
Console.WriteLine("FTP 연결 실패");
return;
}
if (!ftp.DirectoryExists(dstDirPath))
{
Console.WriteLine("경로 없음");
return;
}
// 데이터 복사
Stopwatch stopwatch = Stopwatch.StartNew();
var elapsed = new List<long>();
stopwatch.Start();
for (int i = 0; i < srcFullPath.Length; i++)
{
//ftp.UploadFile(srcFullPath[i], dstFullPath[i]);
ftp.DownloadFile(srcFullPath[i], dstFullPath[i]);
elapsed.Add(stopwatch.ElapsedMilliseconds);
}
stopwatch.Stop();
foreach (var item in elapsed)
{
Console.WriteLine($"{(float)item / 1000} s");
}
ftp.Close();
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}