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...
If you are looking for a Python solution, check out pyftpdlib.
You can install it using e.g. pip:
pip install pyftpdlib
then run it like this:
python -m pyftpdlib
This runs the anonymous-writable FTP server at localhost, port 2121 by default, serving files from the current directory (i.e. from wherever you started it). To login, use anonymous as both username and password.
Obviously, this is very insecure, so you would have to take that into account - if you want anything more then a toy or something to work with in development etc., use a proper FTP server as others mentioned.
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]
One common command line ftp server is vsftpd. This is also the default ftp server on Ubuntu, CentOS, Fedora, NimbleX and RHEL Linux.
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/
Openssh has a SFTP server and the configuration is very easy.
FYI, plain FTP is more complex than HTTP. Take with care :)
精彩评论