Afrowave.SharedTools.Ftp 0.0.1

dotnet add package Afrowave.SharedTools.Ftp --version 0.0.1
                    
NuGet\Install-Package Afrowave.SharedTools.Ftp -Version 0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Afrowave.SharedTools.Ftp" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Afrowave.SharedTools.Ftp" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Afrowave.SharedTools.Ftp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Afrowave.SharedTools.Ftp --version 0.0.1
                    
#r "nuget: Afrowave.SharedTools.Ftp, 0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Afrowave.SharedTools.Ftp@0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Afrowave.SharedTools.Ftp&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Afrowave.SharedTools.Ftp&version=0.0.1
                    
Install as a Cake Tool

Afrowave.SharedTools.Ftp

The Afrowave.SharedTools.Ftp library provides a universal, high-level API for performing common FTP operations such as uploading, downloading, listing, and deleting files or directories. It is fully compatible with .NET Standard 2.1, and designed as a lightweight, dependency-free utility that can be used in desktop, web, and service environments.

This package complements Afrowave.SharedTools.Api by providing the same consistent interface style and dual access pattern:

  • Dependency Injection (DI) service: IFtpService / FtpService
  • Static helper: FtpClientHelper

📦 Contents

Core Options & Configuration

  • Options/FtpOptions.cs – Defines FTP connection parameters (host, credentials, SSL, retry, etc.)
  • Options/RetryPolicyOptions.cs – Exponential backoff retry configuration with optional jitter

Service Layer (Dependency Injection)

  • Interfaces/IFtpService.cs – Defines unified async API for all FTP operations
  • Services/FtpService.cs – Injectable service implementing all core functionality, using FtpWebRequest under the hood

Static Helper Layer

  • Static/FtpClientHelper.cs – Static version mirroring the same API as FtpService, ideal for quick scripting or testing without DI

⚙️ Purpose

Afrowave.SharedTools.Ftp provides an abstraction over the low-level .NET FTP APIs (FtpWebRequest, FtpWebResponse), making file operations simple, consistent, and error-safe. It introduces retry logic, unified response objects, and async support even in .NET Standard 2.1.

This module is ideal for:

  • Automated synchronization of translation dictionaries or localization files
  • CI/CD and DevOps tools for remote file management
  • Lightweight integration with shared file servers

🧩 FtpOptions Example

var options = new FtpOptions
{
    Host = "ftp.example.com",
    Port = 21,
    Credentials = new NetworkCredential("user", "password"),
    EnableSsl = false,
    UsePassive = true,
    Retry = new RetryPolicyOptions
    {
        MaxRetries = 3,
        BaseDelay = TimeSpan.FromMilliseconds(500),
        BackoffFactor = 2.0,
        Jitter = true
    }
};

You can inject these options via DI, appsettings.json, or by directly passing them to the FtpService constructor.


💡 IFtpService (Dependency Injection)

public interface IFtpService
{
    Task<Response<IReadOnlyList<string>>> ListAsync(string remotePath);
    Task<Response<byte[]>> DownloadBytesAsync(string remotePath);
    Task<Result> DownloadToFileAsync(string remotePath, string localFilePath);
    Task<Result> UploadBytesAsync(string remotePath, byte[] data, bool overwrite = true);
    Task<Result> UploadFileAsync(string localFilePath, string remotePath, bool overwrite = true);
    Task<Result> DeleteFileAsync(string remotePath);
    Task<Result> CreateDirectoryAsync(string remotePath);
    Task<Result> DeleteDirectoryAsync(string remotePath);
    Task<Response<long>> GetFileSizeAsync(string remotePath);
    Task<Response<DateTime>> GetModifiedTimeAsync(string remotePath);
    Task<Response<bool>> ExistsAsync(string remotePath);
    Task<Result> RenameAsync(string remotePath, string newName);
}

All methods return Result or Response<T> from the shared Afrowave.SharedTools.Models package for consistency.


🧠 Example Usage (DI)

builder.Services.AddConfiguredService<IFtpService, FtpService, FtpOptions>(cfg =>
{
    cfg.Host = "ftp.example.com";
    cfg.Credentials = new NetworkCredential("demo", "demo123");
    cfg.UsePassive = true;
    cfg.EnableSsl = false;
});

// Later in your service or controller:

public class FtpDemoService
{
    private readonly IFtpService _ftp;

    public FtpDemoService(IFtpService ftp) => _ftp = ftp;

    public async Task UploadAsync()
    {
        var result = await _ftp.UploadFileAsync("local.txt", "/upload/local.txt");
        if (!result.Success) Console.WriteLine($"Failed: {result.Message}");
    }
}

⚡ Static Helper Example

If you prefer not to use DI, the same operations are available via the static helper:

var result = await FtpClientHelper.UploadFileAsync(options, "local.txt", "/remote/local.txt");
if (result.Success)
    Console.WriteLine("File uploaded.");

All static methods take an instance of FtpOptions as their first argument.


🚀 Key Features

Feature Description
.NET Standard 2.1 Works across desktop, web, and service apps
Async/await support Async wrapping around FtpWebRequest for smooth concurrency
Retry logic Configurable exponential retry with optional jitter
Unified result model Uses Result and Response<T> from SharedTools.Models
Stateless static helper For testing, scripting, and quick tools
Supports FTPS Optional SSL/TLS (explicit mode)
Binary + passive mode Defaults to modern secure FTP setup

🧱 Design Principles

  • Type-safe configuration (FtpOptions / RetryPolicyOptions)
  • Separation of static vs DI usage
  • Full async support in .NET Standard 2.1
  • No external dependencies
  • Clear and consistent Afrowave naming conventions

📦 Version 0.0.1 Release Notes

Version Changes
0.0.1 Initial release of Afrowave.SharedTools.Ftp.<br>Includes: <br>• IFtpService / FtpService (DI version)<br>• FtpClientHelper (static version)<br>• FtpOptions and RetryPolicyOptions<br>• Async file and directory operations with retry logic

✍️ This file is part of the multilingual documentation system. Translations will be automatically handled by LangHub.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1 224 10/14/2025