项目作者: sparkeh9

项目描述 :
An FTP library written in C# with no external dependencies
高级语言: C#
项目地址: git://github.com/sparkeh9/CoreFTP.git
创建时间: 2016-09-16T18:24:40Z
项目社区:https://github.com/sparkeh9/CoreFTP

开源协议:MIT License

下载


CoreFTP

NuGet
Build Status: Windows

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/

.NET Framework compatability

CoreFTP Supports and includes compiled binaries for:

  • NetStandard 1.6 and above
  • .NET Framework 4.5.2 and above

Usage

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 an FTP/S server

Connecting to FTP/s supports both Explicit and Implicit modes.

  1. using ( var ftpClient = new FtpClient( new FtpClientConfiguration
  2. {
  3. Host = "localhost",
  4. Username = "user",
  5. Password = "password",
  6. Port = 990,
  7. EncryptionType = FtpEncryption.Implicit,
  8. IgnoreCertificateErrors = true
  9. } ) )
  10. {
  11. await ftpClient.LoginAsync();
  12. }

Downloading a file to a filestream on local disk

  1. using ( var ftpClient = new FtpClient( new FtpClientConfiguration
  2. {
  3. Host = "localhost",
  4. Username = "user",
  5. Password = "password"
  6. } ) )
  7. {
  8. var tempFile = new FileInfo( "C:\\test.png" );
  9. await ftpClient.LoginAsync();
  10. using ( var ftpReadStream = await ftpClient.OpenFileReadStreamAsync( "test.png" ) )
  11. {
  12. using ( var fileWriteStream = tempFile.OpenWrite() )
  13. {
  14. await ftpReadStream.CopyToAsync( fileWriteStream );
  15. }
  16. }
  17. }

Uploading from a local filestream to the FTP server

  1. using ( var ftpClient = new FtpClient( new FtpClientConfiguration
  2. {
  3. Host = "localhost",
  4. Username = "user",
  5. Password = "password"
  6. } ) )
  7. {
  8. var fileinfo = new FileInfo( "C:\\test.png" );
  9. await ftpClient.LoginAsync();
  10. using ( var writeStream = await ftpClient.OpenFileWriteStreamAsync( "test.png" ) )
  11. {
  12. var fileReadStream = fileinfo.OpenRead();
  13. await fileReadStream.CopyToAsync( writeStream );
  14. }
  15. }

Integration Tests

Integration tests can be run against most FTP servers with passive mode enabled, credentials can be configured in appsettings.json of CoreFtp.Tests.Integration.