2 Star 1 Fork 0

cander/ftpserver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Golang FTP Server

Build Cross Build Docker Image Docker test Docker downloads Go Report Card GoDoc

This FTP server is a gateway between old-school FTP devices and modern cloud based file systems, using the afero's Fs interface and acting as a reference implementation of the ftpserverlib.

At the current stage, supported backend are:

And with those are supported common parameters to switch them to read-only, enable logging access, or use a temporary directory file (see doc).

Current status of the project

Features

FTP protocol

These features are brought by ftpserverlib itself:

  • Uploading and downloading files
  • Directory listing (LIST + MLST)
  • File and directory deletion and renaming
  • TLS support (AUTH + PROT)
  • File download/upload resume support (REST)
  • Complete driver for all the above features
  • Passive socket connections (EPSV and PASV commands)
  • Active socket connections (PORT command)
  • Small memory footprint
  • Only relies on the standard library except for:
  • Supported extensions:
    • AUTH - Control session protection
    • AUTH TLS - TLS session
    • PROT - Transfer protection
    • MDTM - File Modification Time
    • SIZE - Size of a file
    • REST - Restart of interrupted transfer
    • MLST - Simple file listing for machine processing
    • MLSD - Directory listing for machine processing

Getting started

Get it

Golang

git clone https://gitee.com/cander/ftpserver.git
cd ftpserver
go build -o ftpserver main.go

Config file

If you don't create a ftpserver.json file, one will be created for you.

Here is a sample config file:

{
   "version": 1,
   "passive_transfer_port_range": {
      "start": 2122,
      "end": 2130
   },
   "tls": {
      "server_cert": {
         "cert": "cert.pem",
         "key": "key.pem"
      }
   },
   "accesses": [
      {
         "user": "test",
         "pass": "test",
         "fs": "os",
         "params": {
            "basePath": "/tmp"
         }
      },
      {
         "user": "test",
         "pass": "test",
         "fs": "os",
         "params": {
            "basePath": "/tmp"
         }
      },
      {
         "user": "dropbox",
         "pass": "dropbox",
         "fs": "dropbox",
         "params": {
            "token": "..."
         }
      },
      {
         "user": "gdrive",
         "pass": "gdrive",
         "fs": "gdrive",
         "params": {
            "google_client_id": "***.apps.googleusercontent.com",
            "google_client_secret": "****"
         }
      },
      {

         "user": "s3",
         "pass": "s3",
         "fs": "s3",
         "params": {
            "endpoint": "https://s3.amazonaws.com",
            "region": "eu-west-1",
            "bucket": "my-bucket",
            "access_key_id": "AKIA....",
            "secret_access_key": "IDxd....",
            "disable_ssl": "false",
            "path_style": "false"
         }
      },
      {
         "user": "sftp",
         "pass": "sftp",
         "fs": "sftp",
         "params": {
            "username": "user",
            "password": "password",
            "hostname": "192.168.168.11:22"
         }
      }
   ]
}

配置文件说明

{
   "version": 1,
   // 被动模式随机的端口
   "passive_transfer_port_range": {
      "start": 2122,
      "end": 2130
   },
   "listen_address": ":2121",  // 监听端口,默认21
   "max_clients": 100,  // 最大客户端限制
   // 证书设置
   "tls": {  
      "server_cert": {
         "cert": "cert.pem",
         "key": "key.pem"
      }
   },
   "accesses": [
      {
         "user": "test",   // ftp 用户名
         "pass": "test",   // ftp 密码
         "fs": "os",       // 标明本地磁盘
         "params": {
            "basePath": "/tmp"   // 本地磁盘根目录, 不存在自动创建
         },
         "read_only": false, // 只读
         "shared": false, // 共享

      },
      {
         "user": "test",
         "pass": "test",
         "fs": "os",
         "params": {
            "basePath": "/tmp"
         }
      },
      {
         "user": "dropbox",
         "pass": "dropbox",
         "fs": "dropbox",
         "params": {
            "token": "..."
         }
      },
      {
         "user": "gdrive",
         "pass": "gdrive",
         "fs": "gdrive",
         "params": {
            "google_client_id": "***.apps.googleusercontent.com",
            "google_client_secret": "****"
         }
      },
      {

         "user": "s3",
         "pass": "s3",
         "fs": "s3",
         "params": {
            "endpoint": "https://s3.amazonaws.com",
            "region": "eu-west-1",
            "bucket": "my-bucket",
            "access_key_id": "AKIA....",
            "secret_access_key": "IDxd....",
            "disable_ssl": "false",
            "path_style": "false"
         }
      },
      {
         "user": "sftp",
         "pass": "sftp",
         "fs": "sftp",
         "params": {
            "username": "user",
            "password": "password",
            "hostname": "192.168.168.11:22"
         }
      }
   ]
}

You can generate the TLS key pair files with the following command:

openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out cert.pem -keyout key.pem

With local binary

You can build the binary and use it directly:

# Get and install the server
go get github.com/fclairamb/ftpserver

ftpserver &

# Download some file
[ -f kitty.jpg ] || (curl -o kitty.jpg.tmp https://placekitten.com/2048/2048 && mv kitty.jpg.tmp kitty.jpg)

# Upload it to the server
curl -v -T kitty.jpg ftp://test:test@localhost:2121/

# Download it back
curl ftp://test:test@localhost:2121/kitty.jpg -o kitty2.jpg

# Compare it
diff kitty.jpg kitty2.jpg

With docker

There's also a containerized version of the server (31MB, based on alpine).

# Starting the sample FTP server
docker run --rm -d -p 2121-2130:2121-2130 -v ./ftpserver/files:/tmp -v ./ftpserver:/app fclairamb/ftpserver

# Download some file
[ -f kitty.jpg ] || (curl -o kitty.jpg.tmp https://placekitten.com/2048/2048 && mv kitty.jpg.tmp kitty.jpg)

# Upload it
curl -v -T kitty.jpg ftp://test:test@localhost:2121/

# Download it back
curl ftp://test:test@localhost:2121/kitty.jpg -o kitty2.jpg

# Compare it
diff kitty.jpg kitty2.jpg

With Docker Compose

# docker-compose.yml

version: '3.3'
services:
  ftpserver:
    ports:
      - '2121-2130:2121-2130'
    volumes:
      - ./ftpserver/files:/tmp
      - ./ftpserver:/app
    image: fclairamb/ftpserver
docker-compose up -d

空文件

简介

ftp go 语言服务 ftpserver fork from https://github.com/fclairamb/ftpserver 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cander/ftpserver.git
git@gitee.com:cander/ftpserver.git
cander
ftpserver
ftpserver
master

搜索帮助