GithubHelp home page GithubHelp logo

black-byte / extensibleftp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from douglasdwyer/extensibleftp

0.0 0.0 0.0 2 MB

ExtensibleFtp provides a customizable, scalable FTP server implementation in .NET.

License: MIT License

C# 99.89% Batchfile 0.11%

extensibleftp's Introduction

Nuget Downloads

ExtensibleFtp

ExtensibleFtp provides a customizable, scalable FTP server implementation in .NET. It comes with a default implementation for anonymous FTP access, and allows for easy addition of new commands, abstract filesystems, and user identities/login schemes.

Referencing ExtensibleFtp

ExtensibleFtp is available as a Nuget package called DouglasDwyer.ExtensibleFtp for inclusion in any .NET project. To include it in your project, either download it using the package manager GUI in Visual Studio, or run the command Install-Package DouglasDwyer.ExtensibleFtp from the Nuget package manager console.

Basic concepts

ExtensibleFtp servers are separated into several classes in order to allow for scalability and easy reconfiguration. The ExtensibleFtpServer class listens for new FTP connections while managing currently connected clients. It contains a list of FtpCommand, which are objects that represent unique actions the user can commit over FTP. The behavior of FTP commands such as USER or PASV is defined by inheriting the FtpCommand abstract class. In addition, the server object contains an IFtpAuthenticator object, which is in charge of managing user accounts. The authenticator is used to implement login behavior (such as checking for a username and password in a database), and generating IFtpIdentity instances, which represent unique user identities and may be used to define various user permissions. In turn, IFtpIdentity objects expose an IFtpFilesystem interface, which is an abstraction over a user filesystem. Custom IFtpFilesystem implementations allow for much flexibility and creativity - files/folders can be hidden, restricted, or even "fabricated" without really existing on the host machine. A complete API reference may be found here.

Getting started

Creating a new server

Starting a new FTP server using C# is as simple as two lines of code! After referencing DouglasDwyer.ExtensibleFtp, one can instantiate FTP servers like this:

ExtensibleFtpServer server = new ExtensibleFtpServer(new AnonymousAuthenticator("C:/Some/Path/"));
server.Start();

This code creates a new server coupled with an AnonymousAuthenticator, an authenticator that allows any connected users access to the specified directory and all of its contents. server.Start() causes the server to begin listening (on port 21 by default).

Adding a custom FTP command

A number of standard FTP commands are included in the ExtensibleFtp implementation. If the need arises to create a new/custom command, though, the implementation is simple - just override the FtpCommand interface and specify the custom behavior. The code for the DELE command is given below:

public class DeleCommand : FtpCommand
{
    public override string CommandName => "DELE";

    public override void Execute(ExtensibleFtpUser user, string path)
    {
        path = Path.Combine(user.CurrentDirectory, path);
        if(user.Filesystem.FileExists(path))
        {
            user.Filesystem.DeleteFile(path);
            user.SendResponse(FtpStatusCode.FileActionOK, "File deleted successfully.");
        }
        else
        {
            throw new FtpException(FtpStatusCode.ActionNotTakenFileUnavailable, "File does not exist.");
        }
    }
}

Instances of the ExtensibleFtpUser class are used to interact with clients. It is separate from IFtpIdentity - the user class allows for actions like sending and receiving FTP messages, whereas an identity identifies a user. Anyhow, to use a custom command with a server, it can either be passed into the ExtensibleFtpServer constructor along with all other commands that the server should use, or it can be added to the ExtensibleFtpServer.DefaultCommandSet list. Any servers instantiated without a specified command set after the command is added to the list will recognize it.

extensibleftp's People

Contributors

douglasdwyer 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.