Categorygithub.com/mindflavor/ftpserver2
modulepackage
0.0.0-20181031211504-1310e1de09a6
Repository: https://github.com/mindflavor/ftpserver2.git
Documentation: pkg.go.dev

# README

Go FTP Secure server with support for local file system and Microsoft Azure Blob storage

License Release Build Status Commits since Coverage Status

A pure go FTP Secure server with support for local file system and Microsoft Azure Blob storage.

The interface based file system makes easy to support different file systems. Please tell me if you are interested in something not covered here.

Features

This server implements most - not all - the FTP commands available. This should be enough for most passive clients, below you will find a tested program list.

The main features are:

  • Local file system support (ie standard FTP)
  • Azure blob storage backed file system
  • Unsecure (plain) FTP
  • FTP Secure explicit
  • FTP Secure implicit
  • File system agnostic
  • Azure nested directory support (thanks to Shuichiro MAKIGAKI)
  • Pluggable logging system (thanks to logrus)

Implemented commands

CommandSince version
USER1.0
PASS1.0
PWD1.0
TYPE1.0
PASV1.0
EPSV1.0
LIST1.0
SYST1.0
CWD1.0
CDUP1.0
SIZE1.0
RETR1.0
STOR1.0
DELE1.0
FEAT1.0
QUIT1.0
NOOP1.0
MKD1.0
RMD1.0
REST1.0
AUTH1.0
PROT1.0
NLST1.1
LIST nested1.1
CWD nested1.1
MKD nested1.1

This list may not be updated: please refer to session.go source file to the updated list.

How to build

The main FTP server object can be called on its own in your project. Here, however, I give you a very simple program to test it. In order to use it download it, compile it and launch it. Here we suppose you have installed GO on your build machine and have the GOPATH environment variable set.

Download

With this command you can download the code with all its references. You can also use it later to update to the latest source code:

go get -u github.com/mindflavor/ftpserver2

Build

To build the application use this code. The binary will be saved in the %GOPATH\bin folder ($GOPATH in linux):

go install github.com/mindflavor/ftpserver2

Use

Here we assume you have a folder called ftphome in your C:\ disk. Substitute it with your FTP home folder.

Windows

%GOPATH%\bin\ftpserver2 -lfs C:\ftphome

Linux

Here we assume you have a folder called /mnt/ftphome on your file system. Substitute it with your FTP home folder.

sudo $GOPATH%/bin/ftpserver2 -lfs /mnt/ftphome

You need to be su in order to listen on port 21 (standard FTP command port). If you use another port you can start the program without sudo. Check the parameters section for how to do it.

Azure blob storage

In order to have the FTP server serve the azure storage blobs simply replace the -lfs parameter with -ak and -an like this:

$GOPATH/bin/ftpserver2 -ak <mystorageaccount> -as <shared_key_primary_or_secondary>

More info on the parameters in the Parameters section.

Some screenshots

This is an example of execution in ubuntu:

As you can see here, TLS is available (it's up to you to use valid certs however):

Here is how an Azure storage account appears in Chrome:

Parameters

At any time you can call the executable with -help flag in order to be reminded of the parameters.

FlagTypeDescriptionDefault
anstringAzure blob storage account name (1)nil
akstringAzure blob storage account key (either primary or secondary) (1)nil
crtstringTLS certificate file (2)nil
keystringTLS certificate key file (2)nil
lDebugstringDebug level log filenil
lErrorstringError level log filenil
lInfostringInfo level log filenil
lWarnstringWarn level log filenil
lfsstringLocal file system root (3)nil
llstringMinimum log level. Available values are Debug, Info, Warn, ErrorInfo
maxPasvPortintHigher passive port range50100
minPasvPortintLower passive port range50000
plainPortintPlain FTP port (unencrypted). If you specify a TLS certificate and key encryption you can pass -1 to start a SFTP implicit server only21
tlsPortintEncrypted FTP port. If you do not specify a TLS certificate this port is ignored. If you specify -1 the implicit SFTP is disabled990

Notes

1.These two flags must be specified together. If you need to retrieve the storage account key look here http://stackoverflow.com/questions/6985921/where-can-i-find-my-azure-account-name-and-account-key. You cannot both specify this flags and the local file system one (lfs).

2.These two flags must be specified together. Without either one the secure extensions of FTP will be disabled. This article (http://stackoverflow.com/questions/12871565/how-to-create-pem-files-for-https-web-server) explains how to generate both the certificate file and the key one.

3.You cannot both specify this flag and the azure storage ones (an and ak).

ToDo

  • Better tests. Coverage is abysmal. Script unit testing for a distributed state machine such as FTP is a PITA though.
  • File access privilege check (right now is ignored).
  • Authentication. Right now the FTPServer delegates authentication to the caller but the provided executable does not validate the passed identity.

Tested clients

PC

Android

License

Please refer here: LICENSE.

Contributing

If you want to contribute please do so, just fork and ask for merge. An huge thank you to everyone contributing (please see here the GitHub contributors page for their names).

# Packages

Package ftp handles the ftp server main class.
Package identity exposes the Identity interface.