Skip to content

Commit

Permalink
test(server.py): use argparse module to parse command line argumets
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskovalchuk committed Mar 29, 2024
1 parent f56df0c commit c785c0e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions test/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@

import os
import logging
import sys
import argparse
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

def main():
if len(sys.argv) != 3:
print("Usage: server.py root_directory port")
return

root_directory = sys.argv[1]
port = sys.argv[2]
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('root_directory')
arg_parser.add_argument('port')
args = arg_parser.parse_args()

# Add user with the following permissions:
# e - change directory (CWD, CDUP commands)
Expand All @@ -47,8 +45,8 @@ def main():
# w - store a file to the server (STOR, STOU commands)
# M - change file mode / permission (SITE CHMOD command)
authorizer = DummyAuthorizer()
authorizer.add_user("user", "password", root_directory, perm = "elradfmwM")
authorizer.add_user("alice", "password", root_directory, perm = "elradfmwM")
authorizer.add_user("user", "password", args.root_directory, perm = "elradfmwM")
authorizer.add_user("alice", "password", args.root_directory, perm = "elradfmwM")

handler = FTPHandler
handler.authorizer = authorizer
Expand All @@ -62,8 +60,8 @@ def main():
logging.StreamHandler()],
level = logging.DEBUG)

server = FTPServer(("127.0.0.1", port), handler)
server = FTPServer(("::1", port), handler)
server = FTPServer(("127.0.0.1", args.port), handler)
server = FTPServer(("::1", args.port), handler)
server.serve_forever()

if __name__ == "__main__":
Expand Down

0 comments on commit c785c0e

Please sign in to comment.