DotFTP 3.0.0

dotnet add package DotFTP --version 3.0.0                
NuGet\Install-Package DotFTP -Version 3.0.0                
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="DotFTP" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotFTP --version 3.0.0                
#r "nuget: DotFTP, 3.0.0"                
#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.
// Install DotFTP as a Cake Addin
#addin nuget:?package=DotFTP&version=3.0.0

// Install DotFTP as a Cake Tool
#tool nuget:?package=DotFTP&version=3.0.0                

DotFTP.NETStandard

DotFTP è una libreria per gestire i seguenti protocolli:

  • FTP
  • FTPS
  • SFTP
  • SCP

consentendo di eseguire le operazioni più comuni quali Upload, Download, Delete e consultazione dei file su host remoto.

Piattaforme supportate

DotFTP ha come target .NET Standard 2.0 ed è quindi compatibile con:

Implementazione .NET Versioni
.NET e .NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Mono 4.6, 5.4, 6.4
Xamarin.iOS 10.0, 10.14, 12.16
Xamarin.Mac 3.0, 3.8, 5.16
Xamarin.Android 7.0, 8.0, 10.0
Piattaforma UWP (Universal Windows Platform) 8.0, 8.1, 10.0, 10.0.16299, TBD
Unity 2018.1

Librerie utilizzate

DotFTP utilizza le librerie open source FluentFTP per FTP, FTPS e SSH.NET per FTPS e SCP

Esempi di utilizzo

DotFTP è molto semplice da utilizzare. Gli esempi riportati si riferiscono all'implementazione dell'interfaccia per FTP/FTPS ma sono sostanzialmente identici per SFTP e SCP. Sarà sufficiente inizializzare l'interfaccia utilizzando SFtpClient e ScpClient rispettivamente

Lettura file nella directory root

using (IFtpClient client = new FtpClient("localhost", "username", "Password"))
{
    try
    {
        client.Connect();
        List<string> files = client.GetFileList("/");
        Console.WriteLine("Elenco file: ");
        foreach (string file in files)
            Console.WriteLine(file);
    }
    catch (Exception ex)
    { Console.WriteLine(ex.Message); }
}

Upload di un file nella cartella /folder

using (IFtpClient client = new FtpClient("localhost", "username", "Password"))
{
    try
    {
        client.Connect();
        client.UploadFile("/folder", @"C:\tmp\DotFTP", "upload.txt");
    }
    catch (Exception ex)
    { Console.WriteLine(ex.Message); }
}

Download di un file da /folder

using (IFtpClient client = new FtpClient("localhost", "username", "Password"))
{
    try
    {
        client.Connect();
        client.DownloadFile("/folder", "upload.txt", @"C:\tmp\DotFTP");
    }
    catch (Exception ex)
    { Console.WriteLine(ex.Message); }
}

Migrazione da IFTPAgent

La migrazione da IFTPAgent a IFtpClient è molto semplice. I metodi hanno mantenuto lo stesso nome e sono semplicemente stati rimossi i parametri host, port, user e pass e quelli rimasti hanno lo stesso ordine e modalità di funzionamento.

Questo è un esempio di come convertire il download di un file:

//Implementazione con IFTPAgent: 
IFTPAgent ftpAgent = new FTPAgent();
    ftpAgent.DownloadFile("localhost", 21, "/", "upload.txt", @"C:\tmp\DotFTP", "username", "Password");

//Implementazione con IFtpClient:
using (IFtpClient client = new FtpClient("localhost", "username", "Password", 21))
{
    try
    {
        client.Connect();
        client.DownloadFile("/folder", "upload.txt", @"C:\tmp\DotFTP");
    }
    catch (Exception ex)
    { Console.WriteLine(ex.Message); }
}

Consigli pratici

  1. L'host può essere specificato sia con il protocollo che senza, quindi è valido sia sftp://serverdomain.com che serverdomain.com
  2. Il path del server FTP deve essere assoluto, quindi partendo dalla root /
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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
3.0.0 469 8/25/2022
2.0.1 422 8/24/2022
2.0.0 391 8/23/2022
1.5.2 422 6/29/2022
1.5.1 446 6/29/2022 1.5.1 is deprecated because it has critical bugs.
1.5.0 431 11/2/2021
1.4.0 492 11/24/2020
1.3.0 843 10/29/2018
1.2.4 926 5/8/2018

Prima versione con supporto a .NET Standard