# How do I temporarily run an FTP server?

In the world of Ubuntu, it seems you either always run an FTP server or you never do. Perhaps I'm the first network analyst who's needed to flash a Cisco, Checkpoint or Nokia image using Ubuntu... I need an FTP server for maybe 5 minutes, no more than that.

I'm looking for a bare-bones, user-initiated FTP server. I understand that it would likely have to run with sudo. That's fine - but I want to start/stop it like a normal program.

On the Windows platform, such tools are a dime a dozen - I've used 3CDaemon for years and recently found CoreFTP. Both are excellent. You configure a user, point it at a directory, then hit the "Start" button. A couple of minutes later, you're generally done and you hit the "Stop" button. Job done.

Such tools don't seem to exist on Ubuntu. I found a Google Code project that creates a TFTP instance reasonably nicely (assuming it still runs - I haven't used it in about a year and python has moved on), but how about FTP? Anything out there?

-
Too bad I haven't had time to finish JetFTP. It does exactly what you describe, and it can run without root privileges (you would have to use a port > 1024 of course). It will run out of the box with no configuration and with a nice GUI too. To get an idea of what it will be like, check out JetHTTP, which is similar in design and interface. –  Nathan Osman Dec 12 '10 at 21:24
Thanks George, I'll check that out too. Perhaps the best of both can be combined. Early days for me and python though, so I doubt I'll be much help there! –  Scaine Dec 13 '10 at 11:23

You can get an FTP server going as easy as one two three using pyftpdlib:

2. run sudo python ftpserver.py
3. there is no step three :)

You now have an ftp server which you can log in to anonymously sharing your home directory. This is meant more as a test of the module, but it does what it says on the tin.

This command:

python ftpserver.py --directory=FTP --port=2121 --write


will serve, without root privileges, on port 2121 and grant write access to anonymous users. It will also use the directory FTP in the current working directory instead of your home. Type python ftpserver.py --help to get information about all the options.

• log into it at anonymous@localhost:2121/

To "install" the application, make it executable (open the file properties, go to permissions, and select executable for all) and move it to /usr/bin (using sudo mv ftpserver.py /usr/bin/ftpserver). You can now start and ftp-server like so:

ftpserver --port=2121 --directory=/home/stefano/Projekte/


Please note that this software is released under the terms of the MIT License, which means you can do basically what ever you please with it. Read the license text, it's only a few lines, and know your rights.

Now, this script doesn't support username and password as part of it's stand-alone functionality (for security reasons I imagine).

You now have, in addition to all options I mentioned, the command line parameters

--username=USERNAME and --password=PASSWORD:

python ftpserver.py --port=2121 --username=ftpuser --password=3r2u389r2u333j


Again, use --help to see them all.

This should be as easy as it gets.

I've also written a little gui for it:

I'm sorry it's 3999 lines long, but it will do everything the original does. And i wanted to keep it all in one file. When it's started without any parameters (i.e. make it executable and double click it, or create a launcher for it), it starts a little gui for you to configure your server. You can still import it as a python module or use the above command line fu.

Known issues:

• I've not bothered with anything other than port 2121. This should be simple, making the port configurable requires complex error handling which I don't want the user to bother with. 2121 should always work fine.

• It won't warn you, like the command line does, about using an insecure configuration. I.e. not setting a password or something like that.

EDIT: since the API of pyftpdlib and ftpserver.py changed (and the ubuntu pastebin links are gone); most of the above post doesn't work anymore. For the (2014) version of pyftpdlib, use this script (ftpserver-cli.py) to achieve the same as above:

#!/usr/bin/env python
# ftpserver-cli.py
import sys
sys.path.append("/path/to/pyftpdlib-svn") # enter your proper path here
import argparse

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

def processCmdLineOptions():
global optparser
optparser = argparse.ArgumentParser(description="ftpserver-cli",
formatter_class=argparse.RawDescriptionHelpFormatter)
default="21", help="port")
default="/home/stefano/Projekte/", help="port")
optargs = optparser.parse_args(sys.argv[1:]) #(sys.argv)
return optargs

optargs = processCmdLineOptions()

print("Using: user: %s pass: %s port: %d dir: %s" % (optargs.username, optargs.password, optargs.port, optargs.directory))

authorizer = DummyAuthorizer()

handler = FTPHandler
handler.authorizer = authorizer

server = FTPServer(("127.0.0.1", optargs.port), handler)
server.serve_forever()


call with:

\$ sudo python ftpserver-cli.py --directory=/tmp/srvtest
Using: user: user pass: 12345 port: 21 dir: /tmp/srvtest
[I 14-03-02 21:40:57] >>> starting FTP server on 127.0.0.1:21, pid=19286 <<<
...

-
This looks like a superb module - since I'm trying to learn python, it sounds like this is a great starting point for building a GUI around... I'm afraid that I'm not marking this as the answer (although I've upvoted it) in the hope that someone knows of a tool that's already GUI based. Thanks for the heads up on this though and thanks for the modified version. –  Scaine Dec 12 '10 at 17:34
Thanks :-) I won't give up, programming a GUI for it now. :P –  Stefano Palazzo Dec 12 '10 at 17:37
Why do you need a GUI? Isn't it sufficient to create a simple launcher (maybe wrap this in a simple script)? –  JanC Dec 12 '10 at 18:33
Thanks Stefano! I never expected that! This is great - not only a GUI to try out (tonight), but also a bit of a teaching guide in how you knocked it together in the first place. Many thanks! –  Scaine Dec 13 '10 at 9:37
paste.ubuntu.com/542726 and paste.ubuntu.com/542852 are dead, unfortunately... also, ftpserver.py changed, and apparently the above post doesn't hold anymore (last standalone revision seems to be r1116, with this diff). I have made an edit to the post with a new script (will be invisible until peer review) –  sdaau Mar 2 '14 at 20:50
• You can use pure-ftpd

• You can use scp if you have an ssh server.

-
Beginners can install a Pure-FTPd server in 5 minutes. It can be as simple as installing the package, typing “pure-ftpd &” and… that’s all. You already have a running server, and clients can start to connect. –  hhlp Dec 12 '10 at 15:40
Yep, I appreciate that Pure is easy, especially with the pure-admin gui package - I use it for my permanent FTP server. However, with PureFTP, you're /always/ running FTP, which is a security risk with a laptop that connects via WIFI. I don't want to have to remember to turn on my firewall and worry about the (probably tiny) resources it consumes. I'm afraid scp isn't usually an option, although some devices are getting better - I think the latest F5 images use scp, as does Cisco's Call Manager these days. –  Scaine Dec 12 '10 at 17:29
I don't even think you need to launch the PureFTP daemon after installing the package. (I thought it was supposed to be started by the postinst script in the package.) –  Nathan Osman Dec 12 '10 at 21:28

For those who copy files to and from routers you might want to try out this tool:

It worked for me and is very easy to configure. It is also a Python script but does tftp instead of ftp. All you have to do is install python-tk and download the script

The only thing to be aware of is that Ubunutu defaults to Phython2 so the best way to start the script is:

sudo python3 ./tftpgui.py

You can then configure it in the GUI. when you are done you press exit and that is it.

Bo

-
Thanks Bo - I'd already mentioned that useful tool in my question. However, I wanted something like TFTPgui for FTP, which didn't exist until Stefano knocked up his python gui. –  Scaine Jan 3 '13 at 16:38
pythons ftplib works fine instead and is much easier to script if dealing with lots of devices(1k+) –  lxx Nov 18 '14 at 4:29