One Line FTP Server

Viewed 11395

A lot of times I used the command, which opens a temporary HTTP server on current directory:

python3 -m http.server

Now I need to receive files, is there any one-line command that opens a ftp server?

I am simply looking for a command line ftp server, no configurations files, no daemons.

I tried Twisted as in One line ftp server in python , but the user has no permission to send files...

5 Answers

Here's a solution using NodeJS (ftp-srv module)

npx ftp-srv ftp://0.0.0.0:2121 --root .

This starts an FTP server listening on TCP port 2121 on all interfaces, which uses the current directory as the root (this is actually the default, so the --root . could be omitted for this particular case) and accepts all logins. (npx downloads the module and runs its main script with the options provided.)

You may also want to check out the --pasv_url option to enable passive mode.

For more details, see https://www.npmjs.com/package/ftp-srv#cli

Options:
  --help             Show help                                         [boolean]
  --version          Show version number                               [boolean]
  --credentials, -c  Load user & pass from json file                    [string]
  --username         Blank for anonymous                  [string] [default: ""]
  --password         Password for given username                        [string]
  --root, -r         Default root directory for users                   [string]
  --read-only        Disable write actions such as upload, delete, etc
                                                      [boolean] [default: false]
  --pasv_url         URL to provide for passive connections             [string]
  --pasv_min         Starting point to use when creating passive connections
                                                        [number] [default: 1024]
  --pasv_max         Ending port to use when creating passive connections
                                                       [number] [default: 65535]

Also you can use twistd:

$ virtualenv try-twisted
$ . try-twisted/bin/activate
(try-twisted) $ pip install twisted[tls]
(try-twisted) $ twistd -n ftp --root=/my/share/dir --password-file=/tmp/pass.dat

and connect to ftp://127.0.0.1:2121 as anonymous

(to deactivate virtualenv run: deactivate)


https://twistedmatrix.com/trac/

Related