simple-ftp-server/ftp_utils.py

23 lines
518 B
Python
Raw Normal View History

2024-03-10 20:33:25 +00:00
class FTPError(Exception):
def __init__(self, message="An unknown error occured", code=-1):
self.message = message
self.code = code
super().__init__(self.message)
def parse_ftp_command(cmd):
tokens = cmd.split(" ")
if len(tokens) == 0:
raise FTPError("No command issued!")
command_name = tokens[0].upper()
arguments = tokens[1:]
return (command_name, arguments)
def get_argument(args, name, index):
try:
return args[index]
except IndexError:
raise FTPError(f"Missing argument '{name}'", 2138)