Файл D:/ftp/docker-compose.yml
version: '3'
services:
ftps:
image: stilliard/pure-ftpd
container_name: ftps
ports:
- "21:21"
- "30000-30009:30000-30009"
volumes:
- "D:/Users/youruser/ftps/data:/home/foo/"
- "D:/Users/youruser/ftps/passwd:/etc/pure-ftpd/passwd"
- "D:/Users/youruser/ftps/ssl:/etc/ssl/private/"
environment:
PUBLICHOST: "0.0.0.0"
FTP_USER_NAME: foo
FTP_USER_PASS: pass
FTP_USER_HOME: /home/foo
ADDED_FLAGS: "--tls=2"
TLS_CN: "localhost"
TLS_ORG: "YourOrg"
TLS_C: "DE"
Выполняем команды для создания образа (docker) и запуска ftps сервера
docker-compose up -d
docker-compose logs -f
Создаем новое консольное приложение на C#...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace ConsoleReadFTPSFolder
{
class Program
{
static void Main(string[] args)
{
var (succeeded, files, errorMessage) = ConnectToFtpsAndReadFilesInDirectory("foo", "pass", "ftp://localhost:21", true, true);
if (succeeded)
{
Console.WriteLine("Show files in FTPS directory:");
foreach (var file in files)
Console.WriteLine(file);
}
else
{
// error
Console.WriteLine($"Error reading directory: {errorMessage}");
}
// wait
Console.ReadLine();
}
private static (bool, IEnumerable<string>, string) ConnectToFtpsAndReadFilesInDirectory(string login, string password, string ftpPath, bool usePassive, bool enableSsl)
{
string fileNames = null;
try
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpPath);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.EnableSsl = enableSsl;
request.UsePassive = usePassive;
request.Credentials = new NetworkCredential(login, password);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(responseStream))
{
fileNames = reader.ReadToEnd();
reader.Close();
}
}
IEnumerable<string> arrFilename = fileNames?.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)?.ToList();
return (true, arrFilename, null);
}
catch (Exception e)
{
return (false, null, e?.Message);
}
}
}
}