FTP - File Transfer Protocol

pcapkit.protocols.application.ftp contains FTP, which implements extractor for File Transfer Protocol (FTP) [*], and FTP_DATA for its data channel.

Changed in version 1.5.0: A command or reply rebuilds byte for byte, its CRLF included, and keeps the command’s case and any octets that are not UTF-8 as captured. A line with no argument and a multi-line reply, whole in one segment or not, parse and rebuild as captured (#1238, #1239, #1240, #1241, #1303, #1333).

class pcapkit.protocols.application.ftp.FTP(file=None, length=None, **kwargs)[source]

Bases: Application[FTP, FTP]

This class implements File Transfer Protocol.

property name: Literal['File Transfer Protocol']

Name of current protocol.

property length: NoReturn

Header length of current protocol.

Raises:

UnsupportedCall – This protocol doesn’t support length.

read(length=None, **kwargs)[source]

Read File Transfer Protocol (FTP).

Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

FTP

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is malformed.

make(cmmd=None, code=None, args=None, more=False, charset=None, raw_cmmd=None, lines=(), **kwargs)[source]

Make (construct) packet data.

The line is terminated with CRLF. Arguments of None write no argument and no separator; otherwise a single SP separates them from the command or code, except after the hyphen of a multi-line reply, which the text follows immediately (RFC 959 Section 4).

Commands are case-insensitive (RFC 959 Section 5), so raw_cmmd is written in place of cmmd whenever the two differ only in case, which keeps the case the command was read in.

Parameters:
  • cmmd (Command | str | bytes | None) – FTP command.

  • code (ReturnCode | int | str | bytes | None) – FTP status code.

  • args (str | bytes | None) – Optional FTP command arguments and/or status messages.

  • more (bool) – More status messages to follow for response packets.

  • charset (str | None) – Encoding for str arguments, UTF-8 if not given.

  • raw_cmmd (bytes | None) – FTP command as received, in its original case.

  • lines (Iterable[bytes]) – Lines of a multi-line reply after the first, each written verbatim and terminated with CRLF; the last, and only the last, is the closing line, <code> SP <text>.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

FTP

Returns:

Constructed packet data.

Raises:

ProtocolError – If neither or both of cmmd and code are given, or if lines are given other than as the rest of a multi-line reply.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (FTP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

class pcapkit.protocols.application.ftp.FTP_DATA(file=None, length=None, **kwargs)[source]

Bases: Raw

This class implements FTP data channel transmission.

property name: Literal['FTP_DATA']

Name of current protocol.

Auxiliary Data

class pcapkit.protocols.application.ftp.Type(*values)[source]

Bases: EnumLookup, StrEnum

FTP packet type.

Built on EnumLookup, the lookup contract shared by every non-registry enumeration (#877). The class defines neither get nor _missing_ of its own.

REQUEST = 'request'

Request packet.

RESPONSE = 'response'

Response packet.

static _generate_next_value_(name, start, count, last_values)

Return the lower-cased version of the member name.

Header Schemas

class pcapkit.protocols.schema.application.ftp.FTP(*args: _VT, **kwargs: _VT)[source]

Bases: Schema

Header schema for FTP packet.

data: bytes = <BytesField data>

Packet data.

Data Models

class pcapkit.protocols.data.application.ftp.FTP(dict_=None, **kwargs)[source]

Bases: Protocol

Data model for FTP protocol.

type: Type

Type.

class pcapkit.protocols.data.application.ftp.Request(*args: VT, **kwargs: VT)[source]

Bases: FTP

Data model for FTP request.

type: Literal[Type.REQUEST]

Type.

cmmd: Command

Command.

args: str | None

Arguments, None if the command carries none.

charset: str | None

Charset to encode args with, None for UTF-8.

raw_cmmd: bytes

Command as received, in its original case; cmmd is the case-insensitive lookup of it.

class pcapkit.protocols.data.application.ftp.Response(*args: VT, **kwargs: VT)[source]

Bases: FTP

Data model for FTP response.

type: Literal[Type.RESPONSE]

Type.

code: ReturnCode

Return code.

args: str | None

Arguments, None if the reply carries no text.

more: bool

More data flag.

charset: str | None

Charset to encode args with, None for UTF-8.

lines: tuple[bytes, ...]

Lines of a multi-line reply after the first, as received and without their CRLF, ending with the closing <code> SP line; empty unless the whole reply arrived at once.

Footnotes