CoreFTP is a simple .NET FTP library written entirely in C#, it is targeted at netstandard 1.6, meaning it will run under .NET Core (which is also where it derives its name) and the full .NET framework. This package was inspired due to a lack of packages providing FTP functionality compiled with support for the netstandard API surface.
NuGet page is at: https://www.nuget.org/packages/CoreFtp/
CoreFTP Supports and includes compiled binaries for:
- NetStandard 1.6 and above
- .NET Framework 4.5.2 and above
Usage of this small library was intended to be as simple as possible. The integration test suite provides various example of basic FTP usage.
Connecting to FTP/s supports both Explicit and Implicit modes.
using ( var ftpClient = new FtpClient( new FtpClientConfiguration
{
Host = "localhost",
Username = "user",
Password = "password",
Port = 990,
EncryptionType = FtpEncryption.Implicit,
IgnoreCertificateErrors = true
} ) )
{
await ftpClient.LoginAsync();
}
using ( var ftpClient = new FtpClient( new FtpClientConfiguration
{
Host = "localhost",
Username = "user",
Password = "password"
} ) )
{
var tempFile = new FileInfo( "C:\\test.png" );
await ftpClient.LoginAsync();
using ( var ftpReadStream = await ftpClient.OpenFileReadStreamAsync( "test.png" ) )
{
using ( var fileWriteStream = tempFile.OpenWrite() )
{
await ftpReadStream.CopyToAsync( fileWriteStream );
}
}
}
using ( var ftpClient = new FtpClient( new FtpClientConfiguration
{
Host = "localhost",
Username = "user",
Password = "password"
} ) )
{
var fileinfo = new FileInfo( "C:\\test.png" );
await ftpClient.LoginAsync();
using ( var writeStream = await ftpClient.OpenFileWriteStreamAsync( "test.png" ) )
{
var fileReadStream = fileinfo.OpenRead();
await fileReadStream.CopyToAsync( writeStream );
}
}
CoreFTP provides several configuration overrides in FtpClientConfiguration to assist with connecting to legacy, obfuscated, or non-compliant FTP servers:
using ( var ftpClient = new FtpClient( new FtpClientConfiguration
{
Host = "legacy-server.local",
Username = "user",
Password = "password",
// Force the control stream encoding for servers that don't support UTF8 (e.g. Chinese GBK or Japanese Shift_JIS)
BaseEncoding = System.Text.Encoding.GetEncoding("GBK"),
// Force the directory listing parser if the server hides its OS in the FEAT response
ForceFileSystem = FtpFileSystemType.Windows,
// Provide a custom callback to validate specific self-signed certificates
IgnoreCertificateErrors = false,
ServerCertificateValidationCallback = (cert, chain, errors) =>
{
return cert.GetCertHashString() == "EXPECTED_THUMBPRINT_HERE";
}
} ) )
{
await ftpClient.LoginAsync();
}Integration tests can be run against most FTP servers with passive mode enabled, credentials can be configured in appsettings.json of CoreFtp.Tests.Integration.