DotFTP 3.0.2
dotnet add package DotFTP --version 3.0.2
NuGet\Install-Package DotFTP -Version 3.0.2
<PackageReference Include="DotFTP" Version="3.0.2" />
<PackageVersion Include="DotFTP" Version="3.0.2" />
<PackageReference Include="DotFTP" />
paket add DotFTP --version 3.0.2
#r "nuget: DotFTP, 3.0.2"
#:package DotFTP@3.0.2
#addin nuget:?package=DotFTP&version=3.0.2
#tool nuget:?package=DotFTP&version=3.0.2
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
- L'host può essere specificato sia con il protocollo che senza, quindi è valido sia sftp://serverdomain.com che serverdomain.com
- Il path del server FTP deve essere assoluto, quindi partendo dalla root /
Product | Versions 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 | 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. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
On FTP Agent is now possibile to specify FtpEncryptionMode