#1916: FTP client STOR request to FTP server

This commit is contained in:
Czar.Echavez
2023-09-20 16:23:35 +01:00
parent f913294058
commit 2e76b3f162
13 changed files with 454 additions and 21 deletions

View File

@@ -5,6 +5,8 @@ from typing import Optional
from pydantic import BaseModel
from primaite.simulator.network.protocols.packet import DataPacket
class ARPEntry(BaseModel):
"""
@@ -18,7 +20,7 @@ class ARPEntry(BaseModel):
nic_uuid: str
class ARPPacket(BaseModel):
class ARPPacket(DataPacket):
"""
Represents the ARP layer of a network frame.

View File

@@ -5,6 +5,8 @@ from typing import Optional
from pydantic import BaseModel
from primaite.simulator.network.protocols.packet import DataPacket
class DNSRequest(BaseModel):
"""Represents a DNS Request packet of a network frame.
@@ -26,7 +28,7 @@ class DNSReply(BaseModel):
"IP Address of the Domain Name requested."
class DNSPacket(BaseModel):
class DNSPacket(DataPacket):
"""
Represents the DNS layer of a network frame.

View File

@@ -0,0 +1,55 @@
from enum import Enum
from typing import Any
from primaite.simulator.network.protocols.packet import DataPacket
class FTPCommand(Enum):
"""FTP Commands that are allowed."""
PORT = "PORT"
"""Set a port to be used for the FTP transfer."""
STOR = "STOR"
"""Copy or put data to the FTP server."""
RETR = "RETR"
"""Retrieve data from the FTP server."""
DELE = "DELE"
"""Delete the file in the specified path."""
RMD = "RMD"
"""Remove the directory in the specified path."""
MKD = "MKD"
"""Make a directory in the specified path."""
LIST = "LIST"
"""Return a list of files in the specified path."""
QUIT = "QUIT"
"""Ends connection between client and server."""
class FTPStatusCode(Enum):
"""Status code of the current FTP request."""
OK = 200
"""Command successful."""
ERROR = 500
"""General error code."""
class FTPPacket(DataPacket):
"""Represents an FTP Packet."""
ftp_command: FTPCommand
"""Command type of the packet."""
ftp_command_args: Any
"""Arguments for command."""
status_code: FTPStatusCode = None
"""Status of the response."""

View File

@@ -0,0 +1,12 @@
from pydantic import BaseModel
class DataPacket(BaseModel):
"""Data packet abstract class."""
packet_payload_size: float = 0
"""Size of the packet."""
def get_packet_size(self) -> float:
"""Returns the size of the packet header and payload."""
return self.packet_payload_size + float(len(self.model_dump_json().encode("utf-8")))