Skip to content

Instantly share code, notes, and snippets.

@Sam-Gram
Last active January 15, 2019 20:42
Show Gist options
  • Save Sam-Gram/a20b88557fa2e45c652d88ce47e878cc to your computer and use it in GitHub Desktop.
Save Sam-Gram/a20b88557fa2e45c652d88ce47e878cc to your computer and use it in GitHub Desktop.
TEMP FTP server in python
#!/usr/bin/env python
# ftpserver-cli.py
# Example use:
# sudo ./test.py --username=login --password=1234 --port=8007 --directory=$PWD
import sys
sys.path.append("/home/sam/.local/lib/python2.7/site-packages") # 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)
optparser.add_argument('-u', '--username', action='store', type=str,
default="user", help="username")
optparser.add_argument('-p', '--password', action='store', type=str,
default="12345", help="password")
optparser.add_argument('-t', '--port', action='store', type=int,
default="21", help="port")
optparser.add_argument('-d', '--directory', action='store', type=str,
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()
authorizer.add_user(optargs.username, optargs.password, optargs.directory, perm="elradfmw")
#authorizer.add_anonymous("/home/nobody")
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer(("0.0.0.0", optargs.port), handler)
server.serve_forever()
#GLWT(Good Luck With That) Public License
#Copyright (c) Everyone, except Author
#The author has absolutely no clue what the code in this project does.
#It might just work or not, there is no third option.
#Everyone is permitted to copy, distribute, modify, merge, sell, publish,
#sublicense or whatever they want with this software but at their OWN RISK.
# GOOD LUCK WITH THAT PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
#0. You just DO WHATEVER YOU WANT TO as long as you NEVER LEAVE A
#TRACE TO TRACK THE AUTHOR of the original product to blame for or hold
#responsible.
#IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
#CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#Good luck.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment