Code Monkey home page Code Monkey logo

ftpserver's Introduction

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 login 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
    • EPRT/EPSV - IPv6 support
    • 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

Download it

Fetch a binary from the latest release and run it.

Build & run it locally

go install github.com/fclairamb/ftpserver@main

ftpserver &

Run it with docker

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

# Creating a directory
mkdir -p files

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

Run it with docker compose

# docker-compose.yml

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

Test it

This is a quick way to see if it's working correctly:

# 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

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": "****",
            "base_path": "ftp"
         }
      },
      {

         "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"
         }
      },
      {
         "user": "telegram",
         "pass": "telegram",
         "fs": "telegram",
         "shared": true,
         "params": {
            "Token": "<OBTAIN_TOKEN_FROM_BOTFATHER>",
            "ChatID": "<INSERT_CHAT_ID_HERE>"
         }
      }
   ]
}

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

ftpserver's People

Contributors

adrianduke avatar andrewarrow avatar asv avatar awskii avatar cablespaghetti avatar dependabot-preview[bot] avatar ernierasta avatar fahman avatar fclairamb avatar fuwn avatar harshavardhana avatar lukino2000 avatar marodere avatar marshallbrekka avatar mgenov avatar probot-auto-merge[bot] avatar renovate-bot avatar renovate[bot] avatar shanmoorthy avatar tennuem avatar wanieru avatar x-way avatar zavla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ftpserver's Issues

help please: use of closed network connection

Version: 0.11.0

Description:

the server received a client connection, but not worked

Error logs:

level=debug ts=2022-06-23T03:38:35.50506839Z caller=server.go:295 component=server clientId=1 clientIp=10.20.15.103:37264 event="Client connected"
level=info ts=2022-06-23T03:38:35.50521604Z caller=server.go:90 component=driver clientId=1 remoteAddr=10.20.15.103:37264 nbClients=1 event="Client connected"
level=error ts=2022-06-23T03:38:35.50597612Z caller=client_handler.go:363 component=server clientId=1 err="set tcp 10.20.15.104:2121: use of closed network connection" event="Network error"
level=error ts=2022-06-23T03:38:35.50706325Z caller=client_handler.go:416 component=server clientId=1 err="read tcp 10.20.15.104:2121->10.20.15.103:37264: use of closed network connection" event="Network error"
level=info ts=2022-06-23T03:38:35.5070922Z caller=server.go:111 component=driver clientId=1 remoteAddr=10.20.15.103:37264 nbClients=0 event="Client disconnected"
level=debug ts=2022-06-23T03:38:35.50711167Z caller=server.go:300 component=server clientId=1 clientIp=10.20.15.103:37264 event="Client disconnected"
level=debug ts=2022-06-23T03:38:35.50712945Z caller=client_handler.go:312 component=server clientId=1 err="close tcp 10.20.15.104:2121->10.20.15.103:37264: use of closed network connection" event="Problem closing control connection"

Do you support building FTP services to the public network? FTP+PASV+NAT routing?

I built it in a device on a local area network
Its ip address is: 192.168.1.111
The port is the default 2122~2130
Other devices can use ftp://192.168.1.111:2121 normally

Then I mapped 192.168.1.111:2121 to the public IP on my openwrt router.

Finally, when I use ftp://domain name or public IP: 2121, it goes wrong, prompting 200 227 error, client I tried windows file browser and several other ftp clients.

In the information returned by the Windows File Explorer 227 error:
In the ip address, it shows the address of the local area network ip, not my public network ip.
The port is random and not 2122~2130 set in the configuration.

Is there an error there?

need help

today at 20:15:27level=info ts=2022-04-29T12:15:27.428684608Z caller=server.go:189 component=server address=[::]:2121 event=Listening...
today at 20:15:27level=info ts=2022-04-29T12:15:27.428809564Z caller=server.go:248 component=server event=Starting...
today at 20:16:26level=debug ts=2022-04-29T12:16:26.820898051Z caller=server.go:295 component=server clientId=1 clientIp=172.17.0.1:46932 event="Client connected"
today at 20:16:26level=info ts=2022-04-29T12:16:26.821004107Z caller=server.go:90 component=driver clientId=1 remoteAddr=172.17.0.1:46932 nbClients=1 event="Client connected"
today at 20:16:43level=info ts=2022-04-29T12:16:43.179706222Z caller=server.go:111 component=driver clientId=1 remoteAddr=172.17.0.1:46932 nbClients=0 event="Client disconnected"
today at 20:16:43level=debug ts=2022-04-29T12:16:43.179844415Z caller=server.go:300 component=server clientId=1 clientIp=172.17.0.1:46932 event="Client disconnected"
today at 20:16:58level=warn ts=2022-04-29T12:16:58.352942536Z caller=client_handler.go:585 component=server clientId=1 error="accept tcp [::]:2127: i/o timeout" event="Unable to open transfer"
today at 20:16:58level=warn ts=2022-04-29T12:16:58.353074201Z caller=client_handler.go:533 component=server clientId=1 err="write tcp 172.17.0.4:2121->172.17.0.1:46932: use of closed network connection" event="Couldn't flush line"
today at 20:17:39level=debug ts=2022-04-29T12:17:39.136880399Z caller=server.go:295 component=server clientId=2 clientIp=172.17.0.1:46950 event="Client connected"
today at 20:17:39level=info ts=2022-04-29T12:17:39.136983059Z caller=server.go:90 component=driver clientId=2 remoteAddr=172.17.0.1:46950 nbClients=1 event="Client connected"

ftps:
image: fclairamb/ftpserver:latest
container_name: ftps
network_mode: "bridge"
restart: unless-stopped
volumes:
- "$DOCKERDIR/Compose/ftps/data:/app"
- "$DOCKERDIR/Compose/ftps/tmp:/tmp"
ports:
- 2121-2130:2121-2130
environment:
- "TZ=$TZ"

I can't connected

Drive API seems to use deprecated OOB flow

Summary

Drive API authentication doesn't work anymore as OOB is not supported anymore.

Error:

Error 400: invalid_request
The out-of-band (OOB) flow has been blocked in order to keep users secure. Follow the Out-of-Band (OOB) flow migration guide linked in the developer docs below to migrate your app to an alternative method.
Request details: redirect_uri=urn:ietf:wg:oauth:2.0:oob

Potential Solution

The migration guide can be found here: https://developers.google.com/identity/protocols/oauth2/resources/oob-migration

when use ftpserver in docker passive mode return ip is inner docker

First of all, thank you for your work.

Recently I used ftpserver in docker,I can't access the FTP server,and I checked the log and found that the IP is wrong.

image

level=info ts=2022-08-25T07:47:14.804465383Z caller=server.go:278 component=server clientId=13 clientIp=10.12.184.1:53969 event="Client connected"
level=info ts=2022-08-25T07:47:14.804529562Z caller=server.go:90 component=driver clientId=13 remoteAddr=10.12.184.1:53969 nbClients=2 event="Client connected"
level=info ts=2022-08-25T07:47:14.820382127Z caller=server.go:111 component=driver clientId=13 remoteAddr=10.12.184.1:53969 nbClients=1 event="Client disconnected"
level=info ts=2022-08-25T07:47:14.820413618Z caller=server.go:283 component=server clientId=13 clientIp=10.12.184.1:53969 event="Client disconnected"
level=info ts=2022-08-25T07:51:05.001546234Z caller=server.go:278 component=server clientId=14 clientIp=10.12.184.1:54624 event="Client connected"
level=info ts=2022-08-25T07:51:05.001613073Z caller=server.go:90 component=driver clientId=14 remoteAddr=10.12.184.1:54624 nbClients=2 event="Client connected"
level=info ts=2022-08-25T07:51:19.54607475Z caller=server.go:111 component=driver clientId=3 remoteAddr=10.12.184.1:53848 nbClients=1 event="Client disconnected"
level=info ts=2022-08-25T07:51:19.546129193Z caller=server.go:283 component=server clientId=3 clientIp=10.12.184.1:53848 event="Client disconnected"
level=info ts=2022-08-25T07:51:25.978445871Z caller=server.go:111 component=driver clientId=14 remoteAddr=10.12.184.1:54624 nbClients=0 event="Client disconnected"
level=info ts=2022-08-25T07:51:25.978517278Z caller=server.go:283 component=server clientId=14 clientIp=10.12.184.1:54624 event="Client disconnected"
level=info ts=2022-08-25T07:51:26.057029238Z caller=server.go:278 component=server clientId=15 clientIp=10.12.184.1:54674 event="Client connected"
level=info ts=2022-08-25T07:51:26.057086958Z caller=server.go:90 component=driver clientId=15 remoteAddr=10.12.184.1:54674 nbClients=1 event="Client connected"
level=info ts=2022-08-25T07:51:30.862116129Z caller=server.go:278 component=server clientId=16 clientIp=10.12.184.1:54689 event="Client connected"
level=info ts=2022-08-25T07:51:30.862176704Z caller=server.go:90 component=driver clientId=16 remoteAddr=10.12.184.1:54689 nbClients=2 event="Client connected"
level=warn ts=2022-08-25T07:51:35.880745106Z caller=client_handler.go:560 component=server clientId=14 error="accept tcp [::]:2123: i/o timeout" event="Unable to open transfer"
level=warn ts=2022-08-25T07:51:35.880821133Z caller=client_handler.go:508 component=server clientId=14 err="write tcp 172.17.0.3:2121->10.12.184.1:54624: use of closed network connection" event="Couldn't flush line"
level=info ts=2022-08-25T07:51:46.172006889Z caller=server.go:111 component=driver clientId=15 remoteAddr=10.12.184.1:54674 nbClients=1 event="Client disconnected"
level=info ts=2022-08-25T07:51:46.172068555Z caller=server.go:283 component=server clientId=15 clientIp=10.12.184.1:54674 event="Client disconnected"
level=warn ts=2022-08-25T07:51:56.079463777Z caller=client_handler.go:560 component=server clientId=15 error="accept tcp [::]:2122: i/o timeout" event="Unable to open transfer"
level=warn ts=2022-08-25T07:51:56.079518483Z caller=client_handler.go:508 component=server clientId=15 err="write tcp 172.17.0.3:2121->10.12.184.1:54674: use of closed network connection" event="Couldn't flush line"
level=info ts=2022-08-25T07:52:06.174172589Z caller=server.go:111 component=driver clientId=16 remoteAddr=10.12.184.1:54689 nbClients=0 event="Client disconnected"
level=info ts=2022-08-25T07:52:06.17422014Z caller=server.go:283 component=server clientId=16 clientIp=10.12.184.1:54689 event="Client disconnected"
level=info ts=2022-08-25T07:52:06.214912206Z caller=server.go:278 component=server clientId=17 clientIp=10.12.184.1:54772 event="Client connected"
level=info ts=2022-08-25T07:52:06.214945154Z caller=server.go:90 component=driver clientId=17 remoteAddr=10.12.184.1:54772 nbClients=1 event="Client connected"
level=warn ts=2022-08-25T07:52:16.180050938Z caller=client_handler.go:560 component=server clientId=16 error="accept tcp [::]:2129: i/o timeout" event="Unable to open transfer"
level=warn ts=2022-08-25T07:52:16.180106505Z caller=client_handler.go:508 component=server clientId=16 err="write tcp 172.17.0.3:2121->10.12.184.1:54689: use of closed network connection" event="Couldn't flush line"
level=warn ts=2022-08-25T07:52:36.233843081Z caller=client_handler.go:560 component=server clientId=17 error="accept tcp [::]:2123: i/o timeout" event="Unable to open transfer"
level=info ts=2022-08-25T08:05:26.121172284Z caller=server.go:111 component=driver clientId=17 remoteAddr=10.12.184.1:54772 nbClients=0 event="Client disconnected"
level=info ts=2022-08-25T08:05:26.121277481Z caller=server.go:283 component=server clientId=17 clientIp=10.12.184.1:54772 event="Client disconnected"
level=info ts=2022-08-25T08:05:53.986240018Z caller=server.go:278 component=server clientId=18 clientIp=10.12.184.1:56951 event="Client connected"
level=info ts=2022-08-25T08:05:53.986339175Z caller=server.go:90 component=driver clientId=18 remoteAddr=10.12.184.1:56951 nbClients=1 event="Client connected"
level=warn ts=2022-08-25T08:06:25.673047236Z caller=client_handler.go:560 component=server clientId=18 error="accept tcp [::]:2128: i/o timeout" event="Unable to open transfer"

image

read: connection reset by peer

level=info ts=2022-04-24T10:13:32.751669412Z caller=server.go:189 component=server address=[::]:2121 event=Listening...
level=info ts=2022-04-24T10:13:32.751782054Z caller=server.go:245 component=server event=Starting...
level=debug ts=2022-04-24T10:13:50.92146647Z caller=server.go:292 component=server clientId=1 clientIp=192.168.1.7:53217 event="Client connected"
level=info ts=2022-04-24T10:13:50.921627698Z caller=server.go:90 component=driver clientId=1 remoteAddr=192.168.1.7:53217 nbClients=1 event="Client connected"
level=error ts=2022-04-24T10:13:51.817900056Z caller=client_handler.go:416 component=server clientId=1 err="read tcp 172.29.0.2:2121->192.168.1.7:53217: read: connection reset by peer" event="Network error"
level=info ts=2022-04-24T10:13:51.817980079Z caller=server.go:111 component=driver clientId=1 remoteAddr=192.168.1.7:53217 nbClients=0 event="Client disconnected"
level=debug ts=2022-04-24T10:13:51.818011902Z caller=server.go:297 component=server clientId=1 clientIp=192.168.1.7:53217 event="Client disconnected"

access denied 530

curl -v -T 2.jpg "ftp://***:***@[2a00:1ed0:1000::2:f]:21"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 2a00:1ed0:1000::2:f...
* TCP_NODELAY set
* Connected to 2a00:1ed0:1000::2:f (2a00:1ed0:1000::2:f) port 21 (#0)
< 220 ftpserver
> USER ***
< 331 OK
> PASS ***
< 530 Authentication problem: unknown user
* Access denied: 530
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Closing connection 0
curl: (67) Access denied: 530

user / pass definitely matches my ftpserver.json

{
  "version": 1,
  "accesses": [
    {
      "user": "***",
      "pass": "***",
      "fs": "s3",
      "params": {
         "endpoint": "https://s3.app.zerops.io",
         "region": "us-east-1",
         "bucket": "storage",
         "access_key_id": "***",
         "secret_access_key": "***",
         "disable_ssl": "true",
         "path_style": "true"
      }
   }
  ]
}

how would I go about debugging this?

(note that there's a balancer inside the service which forwards public port 21 to internal port 2121, the service is definitely running)

docker run command failed "./ftpserver" includes invalid characters for a local volume name

Simply referring the path ./ftpserver is giving the following error.

$ docker run --rm -d -p 2121-2130:2121-2130 -v ./ftpserver/files:/tmp -v ./ftpserver:/app fclairamb/ftpserver
docker: Error response from daemon: create ./ftpserver/files: "./ftpserver/files" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.

Docker version

Client: Docker Engine - Community
 Version:           20.10.0
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        7287ab3
 Built:             Tue Dec  8 18:54:00 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.0
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       eeddea2
  Built:            Tue Dec  8 18:58:04 2020
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad

It is also happening in the latest version of docker as of today 20.10.11+dfsg1.

Solution

  1. Give full path
  2. Give reference to current path $PWD or $(pwd)

Working

$  docker run --rm -d -p 2121-2130:2121-2130 -v $PWD/ftpserver/files:/tmp -v $PWD/ftpserver:/app fclairamb/ftpserver
3c9806f6e7067fb03e05107669c67b10c1a32294d434824b31c36bea5469926d

Let me know If I can submit the PR for this issue to edit the README.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

AWS S3 Credentials via Environment Variables?

Hi,

Is there currently a way to provide the AWS credentials through the standard environment variables .e.g AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY? This would be better for my use case of running on Kubernetes.

Many Thanks

Directories are missing in the list on S3 backend

I ran ftpserver on S3 backend and found that I could only list files. Is this not implemented yet?

If I enter a directory path directly in FTP client, I could list files for that directory, but subdirectory is missing.

I built manually from cb048f8 .

I modified AWS session initialization code because it doesn't currently allow configuring credentials from EC2 metadata server. That's the only change I made to the server.

couldn't use multiple user with config json file

I'm using this with docker and updated config file for multiple users,
but it seems the first user can connect but the rest users couldn't connect.
can anyone help me with this, or just tell me what am I doing wrong?

Here is the config file,

{
  "version": 1,
  "passive_transfer_port_range": {
    "start": 2122,
    "end": 2130
  },
  "accesses": [
    {
      "user": "rilus",
      "pass": "@rilus",
      "fs": "os",
      "params": {
        "basePath": "/tmp"
      }
    },
    {
      "user": "rafi",
      "pass": "@rafi",
      "fs": "os",
      "params": {
        "basePath": "/tmp"
      }
    },
    {
      "user": "sakib",
      "pass": "@sakib",
      "fs": "os",
      "params": {
        "basePath": "/tmp"
      }
    }
  ]
}

Problem with Java's FTP client

I have created an FTP container using docker and can successfully upload and download files using tools such as WinSCP and CURL. However, when I use Java's FTP client to connect and download files, I am able to establish a connection but cannot retrieve any files from the FTP server. What could be the reason behind this issue?Below is my code:

    public static void main(String[] args) {
        String server = "127.0.0.1";
        int port = 2121;
        String user = "test";
        String password = "test";
        String remoteFile = "1.png";
        String localFile = "/test.png";

        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient.connect(server, port);
            ftpClient.login(user, password);
            ftpClient.enterLocalPassiveMode();
            FTPFile[] ftpFiles = ftpClient.listFiles();
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            OutputStream outputStream = new FileOutputStream(localFile);
            ftpClient.retrieveFile(remoteFile, outputStream);
            outputStream.close();

            ftpClient.logout();
            ftpClient.disconnect();
            System.out.println("File downloaded successfully");
        } catch (IOException ex) {
            System.out.println("Error downloading file: " + ex.getMessage());
            ex.printStackTrace();
        }
    }

basePath use to gdrive

Hello

Can we make user specific folder selection?

I am unfamiliar with go language :(
I would be very happy if you could help with this.

your project is very good :)
thank you.

  {
     "user": "gdrive",
     "pass": "gdrive",
     "fs": "gdrive",
     "params": {
        "google_client_id": "***.apps.googleusercontent.com",
        "google_client_secret": "****",
        **"basePath": "backup"**
     }
  },

go get -u error

go get: installing executables with 'go get' in module mode is deprecated.
        To adjust and download dependencies of the current module, use 'go get -d'.
        To install using requirements of the current module, use 'go install'.
        To install ignoring the current module, use 'go install' with a version,
        like 'go install example.com/cmd@latest'.
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.
go get: added cloud.google.com/go v0.94.1

support show ip

image

when I use this command, it not show ip
i must use second command to show ip with ifconfig

so, don't use two command ,just only use fptserver command

Logging caller is broken

level=warn ts=2020-07-07T20:22:15.673864323Z caller=go-kit.go:21 confFile=ftpserver.json event="No conf file, creating one"
level=info ts=2020-07-07T20:22:15.676738022Z caller=go-kit.go:21 component=server address=[::]:2121 event=Listening...
level=info ts=2020-07-07T20:22:15.676991668Z caller=go-kit.go:21 component=server event=Starting...

can't list S3 remotes

Hi,

im using scaleway's s3 solution as remote backend:

    "fs": "s3",                                                                                                                                                
         "params": {                                                                                                                                             
            "endpoint": "https://s3.fr-par.scw.cloud",                                                                                                           
            "region": "fr-par",                                                                                                                                  
            "bucket": "ftpserver",                                                                                                                               
            "access_key_id": "SCWxxx",                                                                                                             
            "secret_access_key": "xxxx,                                                                                         
            "disable_ssl": "true",                                                                                                                               
            "path_style": "true"                                                                                                                                 
         }  ,           

Unfortunately a simple ls command show nothing:
image

Is there any advice which can help?

thanks

Docker env vars for accesses

I was looking for env vars to be used in the "accesses" part of the ftpserver.json, but couldn't find any. After looking at the Dockerfile, I think this is just not implemented at this time.
Am I right or did I miss something ? Are you planning on implementing this ?
I found 1 or 2 simple workarounds, I'll comment here if everything work, for future usages.

curl works but doesn't any ftp client

Hello!
I run ftpserver on my vps with docker-compose.yml:

version: '3.3'
services:
    ftpserver:
        ports:
            - '2121-2130:2121-2130'
        volumes:
            - /home/ftp/shared:/tmp
            - /home/ftp:/app
        image: fclairamb/ftpserver

I also add vps public ip .env file:

PUBLIC_HOST=45.67.57.2

file ftpserver.json has been created automatically

{
  "version": 1,
  "accesses": [
    {
      "user": "test",
      "pass": "test",
      "fs": "os",
      "params": {
        "basePath": "/tmp"
      }
    }
  ],
  "passive_transfer_port_range": {
    "start": 2122,
    "end": 2130
  }
}

When I run command on my local computer (not vps) from wsl

curl ftp://test:[email protected]:2121

I get list of files:
image

But if I try to connect with any ftp client, I get something like this:
image

how can i change the Listenport

how can i change the Listenport?

i try config the josn l like this ,but not work
{ "version": 1, "ListenAddress":"0.0.0.0:8889", "accesses": [ { "user": "test", "pass": "test", "fs": "os", "params": { "basePath": "../tmp" } } ], "passive_transfer_port_range": { "start": 2121, "end": 2130 } }

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile
  • golang 1.22-alpine
Dockerfile.alpine
  • golang 1.22-alpine
  • alpine 3.20.1
github-actions
.github/workflows/build.yml
  • actions/checkout v4.1.7
  • golangci/golangci-lint-action v6
  • actions/setup-go v5.0.2
  • ubuntu 22.04
.github/workflows/codeql-analysis.yml
  • actions/checkout v4.1.7
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
  • ubuntu 22.04
.github/workflows/docker-test.yml
  • ubuntu 22.04
.github/workflows/docker.yml
  • actions/checkout v4.1.7
  • actions/setup-go v5.0.2
  • docker/metadata-action v5
  • docker/setup-qemu-action v3
  • docker/setup-buildx-action v3
  • actions/cache v4
  • docker/login-action v3
  • docker/login-action v3
  • docker/build-push-action v5
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/goreleaser.yml
  • actions/checkout v4.1.7
  • actions/setup-go v5.0.2
  • goreleaser/goreleaser-action v5.1.0
  • ubuntu 22.04
.github/workflows/jsonschema.yml
  • actions/checkout v4.1.7
  • python 3.11-alpine3.16
  • ubuntu 22.04
gomod
go.mod
  • go 1.21
  • go 1.22.5
  • github.com/aws/aws-sdk-go v1.54.19
  • github.com/fclairamb/afero-dropbox v0.1.0
  • github.com/fclairamb/afero-gdrive v0.3.0
  • github.com/fclairamb/afero-s3 v0.3.1
  • github.com/fclairamb/afero-snd v0.1.0
  • github.com/fclairamb/ftpserverlib v0.24.1
  • github.com/fclairamb/go-log v0.5.0
  • github.com/go-mail/mail v2.3.1+incompatible
  • github.com/pkg/sftp v1.13.6
  • github.com/spf13/afero v1.11.0
  • github.com/tidwall/sjson v1.2.5
  • golang.org/x/crypto v0.25.0
  • golang.org/x/oauth2 v0.21.0
  • gopkg.in/telebot.v3 v3.3.6
  • github.com/go-kit/log v0.2.1

  • Check this box to trigger a request for Renovate to run again on this repository

Support symlinks

Hello,
ftpserver does not support symlinks yet, they're just ignored. It would be very nice if it would be supported! Thank you!

No way to turn off debug mode

The server prints all command sent to it, and PASS command is no exception. Since debug mode is always on and not configurable, it's not possible to turn this off without editing source code.

And if I turn off debug mode by removing this line, the server does not log anything except for connected and disconnected events. Ideally, I would live the server to log about uploaded files.

cc.SetDebug(true)

Couldn't flush line :: Error: Failed to retrieve directory listing

I am unable to connect with ftpserver what's wrong?
Server log:

root@mostain:~/ftps# ./ftpserver
level=info version= date= commit= event="FTP server"
level=info component=server address=[::]:2121 event=Listening...
level=info component=server event=Starting...
level=debug component=server clientId=1 clientIp=103.124.226.98:61928 event="Client connected"
level=info component=driver clientId=1 remoteAddr=103.124.226.98:61928 nbClients=1 event="Client connected"
level=info component=driver clientId=1 remoteAddr=103.124.226.98:61928 nbClients=0 event="Client disconnected"
level=debug component=server clientId=1 clientIp=103.124.226.98:61928 event="Client disconnected"
level=debug component=server clientId=2 clientIp=103.124.226.98:61940 event="Client connected"
level=info component=driver clientId=2 remoteAddr=103.124.226.98:61940 nbClients=1 event="Client connected"
level=warn component=server clientId=1 error="accept tcp [::]:2125: i/o timeout" event="Unable to open transfer"
level=warn component=server clientId=1 err="write tcp 209.126.12.223:2121->103.124.226.98:61928: use of closed network connection" event="Couldn't flush line"
level=info component=driver clientId=2 remoteAddr=103.124.226.98:61940 nbClients=0 event="Client disconnected"
level=debug component=server clientId=2 clientIp=103.124.226.98:61940 event="Client disconnected"
level=warn component=server clientId=2 error="accept tcp [::]:2126: i/o timeout" event="Unable to open transfer"
level=warn component=server clientId=2 err="write tcp 209.126.12.223:2121->103.124.226.98:61940: use of closed network connection" event="Couldn't flush line"

FileZilla client log:

Status:	Connecting to 209.126.12.223:2121...
Status:	Connection established, waiting for welcome message...
Response:	220 ftpserver
Command:	AUTH TLS
Response:	550 Cannot get a TLS config: not enabled
Command:	AUTH SSL
Response:	550 Cannot get a TLS config: not enabled
Status:	Insecure server, it does not support FTP over TLS.
Command:	USER test
Response:	331 OK
Command:	PASS ****
Response:	230 Password ok, continue
Command:	SYST
Response:	215 UNIX Type: L8
Command:	FEAT
Response:	211- These are my features
Response:	 CLNT
Response:	 UTF8
Response:	 SIZE
Response:	 MDTM
Response:	 REST STREAM
Response:	 EPRT
Response:	 EPSV
Response:	 MLSD
Response:	 MLST
Response:	 MFMT
Response:	211 end
Command:	CLNT FileZilla
Response:	200 Good to know
Command:	OPTS UTF8 ON
Response:	200 I'm in UTF8 only anyway
Status:	Logged in
Status:	Retrieving directory listing...
Command:	PWD
Response:	257 "/" is the current directory
Command:	TYPE I
Response:	200 Type set to binary
Command:	PASV
Response:	227 Entering Passive Mode (209,126,12,223,8,77)
Command:	MLSD
Error:	Connection timed out after 20 seconds of inactivity
Error:	Failed to retrieve directory listing
Status:	Disconnected from server
Status:	Connecting to 209.126.12.223:2121...
Status:	Connection established, waiting for welcome message...
Status:	Insecure server, it does not support FTP over TLS.
Status:	Logged in
Status:	Retrieving directory listing...
Command:	PWD
Response:	257 "/" is the current directory
Command:	TYPE I
Response:	200 Type set to binary
Command:	PASV
Response:	227 Entering Passive Mode (209,126,12,223,8,78)
Command:	MLSD
Error:	Connection timed out after 20 seconds of inactivity
Error:	Failed to retrieve directory listing

Remote connection problem

I run the ftpserver service with Docker using the example ftpserver.json configuration.
With the local cli examples of uploading & downloading a jpeg image, it works perfect. I see that the image is saved in the /tmp folder inside the container.

But I can't access FTP using remote "softwares" like telnet, Cyberduck, Filezilla, or Google Chrome (ftp://).
I tried to re-install the container several times, but the error persists.

It seems that it doesn't recognize remote location and tries to connect locally when you want to fetch the list.

gabriel@gf-debian:~$ docker ps
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                                   NAMES
06b1859199c5        fclairamb/ftpserver   "/bin/ftpserver"    12 hours ago        Up 8 minutes        0.0.0.0:2121->2121/tcp, 2122-2130/tcp   eloquent_raman

Local CLI example, works:

gabriel@gf-debian:~/Downloads$ ls -l | grep kitty
-rw-r--r--  1 gabriel gabriel    254776 Dec  7 10:36 kitty2.jpg
-rw-r--r--  1 gabriel gabriel    254776 Dec  7 10:36 kitty.jpg

From remote PC:

gabriel@Gabriels-MacBook-Pro ~ % telnet 10.20.23.23 2121
Trying 10.20.23.23...
Connected to debian.gf.
Escape character is '^]'.
220 ftpserver
USER test
331 OK
PASS test
230 Password ok, continue
CWD /
250 CD worked on /
PASV
227 Entering Passive Mode (172,17,0,2,8,77)
NLST /
425 Unable to open transfer: accept tcp [::]:2125: i/o timeout

Filezilla & Cyberduck errors:

Screen Shot 2020-12-07 at 10 44 05 AM

Screen Shot 2020-12-07 at 10 46 09 AM

cannot find package dropbox

$ go get github.com/fclairamb/ftpserver
cannot find package "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox" in any of:
        /usr/local/Cellar/go/1.15/libexec/src/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox (from $GOROOT)
        /Users/fxck/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox (from $GOPATH)
cannot find package "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files" in any of:
        /usr/local/Cellar/go/1.15/libexec/src/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files (from $GOROOT)
        /Users/fxck/go/src/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files (from $GOPATH)
        

SFTP Issue - command=SSH-2.0-PUTTY_SNAPSHOT_2020_10_10.6538308 event="Unknown command"

Just found this repo and looking to get this setup on my local network.

This is my current config file:

{
  "version": 1,
  "passive_transfer_port_range": {
    "start": 2122,
    "end": 2130
  },
  "accesses": [
    {
      "user": "test",
      "pass": "test",
      "fs": "os",
      "params": {
        "basePath": "/"
      }
    },
    {
      "user": "sftp",
      "pass": "sftp",
      "fs": "sftp",
      "params": {
        "user": "sftp2",
        "pass": "sftp2",
        "hostname": "192.168.68.103:22",
      }
    }
  ]
}

As you see, I have an accessor for vanilla FTP and an accessor for SFTP. My server's local IP address is 192.168.68.105, and I'm trying to connect to the server via my iPhone's FTPManager Pro version app. The parameters I've set in the app look like this for the SFTP connection:

image2

(Sorry, the port should say 2121 for reproducibility, not 22)

When I try to connect to the server, the log says this:

level=debug component=server clientId=5 clientIp=192.168.68.103:64823 event="Client connected"
level=info component=driver clientId=5 remoteAddr=192.168.68.103:64823 nbClients=2 event="Client connected"
level=warn component=server clientId=5 command=SSH-2.0-PUTTY_SNAPSHOT_2020_10_10.6538308 event="Unknown command"

When I run the diagnose feature on the app, I see this output, which is good:

image3

So it sees the server and is able to communicate with it, but the server is rejecting some putty command? It makes me think I'm not setting up the params in the app or the config file correctly.

I've tried many combinations of username/password/port specifications in both the app and the config to no avail so far, so I'm opening it up here to see if I can get this figured out. I AM able to connect to the server via the app with the vanilla FTP parameters/config, but looking to switch to SFTP. Thanks!

TLS Configuration Options

There doesn't seem to be a way in the configuration to specify any configuration options for TLS for the FTP Server

Some s3 service's capability of directory

In some s3 capable service such as minio , directory such as root / , not recognized as directory by api, so ftp client can't list directory.
In this case, could we just treat path name with suffix / as directory?
I had try it without thoughtful, it seams well.

diff --git a/handle_dirs.go b/handle_dirs.go
index e2c9cbb..08560f1 100644
--- a/handle_dirs.go
+++ b/handle_dirs.go
@@ -30,7 +30,7 @@ func (c *clientHandler) handleCWD(param string) error {
 	p := c.absPath(param)
 
 	if stat, err := c.driver.Stat(p); err == nil {
-		if stat.IsDir() {
+		if stat.IsDir() || strings.HasSuffix(p, "/") { /*treat / suffix as directory*/
 			c.SetPath(p)
 			c.writeMessage(StatusFileOK, fmt.Sprintf("CD worked on %s", p))
 		} else {
@@ -325,7 +325,7 @@ func (c *clientHandler) getFileList(param string, filePathAllowed bool) ([]os.Fi
 		return nil, err
 	}
 
-	if !info.IsDir() {
+	if !info.IsDir() && !strings.HasSuffix(listPath, "/") { /*treat / suffix as directory*/
 		if filePathAllowed {
 			return []os.FileInfo{info}, nil
 		}

SetBinaryMode

Hello, how to set the transmission in binary form, if the file name contains other languages, the file name will be garbled.Thanks

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.