Skip to content

gufo.blob.aio.ftp

Async FTPBlob implementation.

FTPBlob

Bases: BlobBase

Async FTP blob backend using native asyncio.

Stores objects as files on a remote FTP server (passive mode). All operations use asyncio streams and never block the event loop.

Only passive mode is supported. Active mode (PORT/EPRT), TLS (FTPS), and resume operations (REST) are not implemented.

Parameters:

Name Type Description Default
host str

FTP server hostname or address.

required
port int

FTP server port (default 21).

21
user str

Login username.

DEFAULT_USER
password str

Login password.

DEFAULT_PASSWORD
root str

Root directory prefix on the remote server.

''
timeout float

Operation and socket connect timeout in seconds.

30.0
retries int

Connection retry attempts on failure.

3
retry_timeout float

Base delay between connection retries.

1.0
features FTPFeatures | None

Optional explicit :class:FTPFeatures. When provided, FEAT won't be probed lazily.

None

connection async property

Get connected reader and writer.

Returns:

Type Description
_Conn

Connected streams that have passed login.

Raises:

Type Description
BlobError

on error.

features async property

Get FTP server features.

Lazily probed via FEAT on first access after connection.

Returns:

Name Type Description
Parsed FTPFeatures

class:FTPFeatures.

close() async

Perform cleanup routines when necessary.

delete(key) async

Delete key.

Parameters:

Name Type Description Default
key str

Object key.

required

Raises:

Type Description
KeyError

If the key does not exist.

BlobError

On backend or I/O failure.

exists(key) async

Check whether a key exists on the server.

Uses SIZE first (if supported), then MLST, and falls back to scanning via LIST when neither is available.

Parameters:

Name Type Description Default
key str

Object key.

required

Returns:

Type Description
bool

True if the key exists as a file, False otherwise.

Raises:

Type Description
BlobError

On backend or I/O failure.

get(key) async

Retrieve data by key.

Parameters:

Name Type Description Default
key str

Object key.

required

Returns:

Type Description
bytes

Stored bytes.

Raises:

Type Description
KeyError

If the server reports 550 (file not found).

BlobError

On backend or I/O failure.

open() async

Perform connection routines when necessary.

Raises:

Type Description
BlobError

on error.

parse_url(url) classmethod

Parse FTP URL and extract parameters for constructor.

Parameters:

Name Type Description Default
url str

URL to parse.

required

Returns:

Type Description
dict[str, Any]

**kwargs for constructor.

put(key, data) async

Store binary data under the given key.

Creates intermediate remote directories automatically via MKD. If the key already exists, its value is overwritten.

Parameters:

Name Type Description Default
key str

Object key (remote path).

required
data bytes

Binary payload.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

scan(prefix)

Iterate all keys within prefix.

Uses MLSD when available, falling back to LIST.

Parameters:

Name Type Description Default
prefix str

Prefix to scan. Empty string scans root.

required

Returns:

Type Description
AsyncIterator[str]

Yields matched keys.

Raises:

Type Description
BlobError

On backend or I/O failure.