GithubHelp home page GithubHelp logo

codefork / coreftp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sparkeh9/coreftp

0.0 2.0 0.0 515 KB

An FTP library written in C# with no external dependencies

License: MIT License

C# 100.00%

coreftp's Introduction

CoreFTP

NuGet Build Status: Windows

CoreFTP is a simple .NET FTP library written entirely in C#, it is targeted at netstandard 1.3, 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.3 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.

using ( var ftpClient = new FtpClient( new FtpClientConfiguration
                                             {
                                                 Host = "localhost",
                                                 Username = "user",
                                                 Password = "password",
                                                 Port = 990,
                                                 EncryptionType = FtpEncryption.Implicit,
                                                 IgnoreCertificateErrors = true
                                             } ) )
{
    await ftpClient.LoginAsync();
}

Downloading a file to a filestream on local disk

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 );
        }
    }
}

Uploading from a local filestream to the FTP server

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 );
    }
}

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.

coreftp's People

Contributors

sparkeh9 avatar guilhermelabigalini avatar mormegil-cz avatar jaime-olivares avatar hamuma avatar

Watchers

James Cloos avatar Gorel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.