Skip to content

gufo.blob.sync.ftp

FTPBlob implementation.

FTPBlob

Bases: BlobBase

FTP-based synchronous blob storage.

This backend stores objects as files on a remote FTP server using standard passive mode (PASV). The object key is used directly as the remote file path relative to the configured root directory.

The implementation is intentionally minimal and supports only the subset of FTP commands required by the Blob API:

  • USER/PASS
  • PASV
  • RETR
  • STOR
  • DELE
  • CWD
  • QUIT

Additional commands may be optionally used when supported by server:

  • MLSD
  • MLST
  • SIZE

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

All sockets use configurable timeouts to avoid indefinite blocking.

The backend assumes that keys are valid FTP path names and does not perform any path normalization beyond using the configured root directory.

Parameters:

Name Type Description Default
host str

FTP host.

required
port int

FTP port.

21
user str

FTP user.

DEFAULT_USER
password str

FTP password.

DEFAULT_PASSWORD
root str

root directory.

''
timeout float

connection and operation timeout in seconds.

30.0
retries int

number of connection retries.

3
retry_timeout float

retry timeout in seconds.

1.0
features FTPFeatures | None

set FTPFeatures explicitly.

None

connection property

Get connected socket.

Returns:

Type Description
socket

Connected socket which passes login.

Raises:

Type Description
BlobError

on error.

features cached property

Get FTP server features.

Lazy evaluated on the first call of connection.

close()

Perform cleanup routines when necessary.

delete(key)

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)

Check whether a key exists in the blob store.

Uses MLST (RFC 3659) if the server supports it; falls back to LIST <key> for servers that lack RFC 3659 support.

Parameters:

Name Type Description Default
key str

Object key.

required

Returns:

Type Description
bool

True if the key exists, False otherwise.

Raises:

Type Description
BlobError

On backend or I/O failure.

get(key)

Retrieve data by key.

Parameters:

Name Type Description Default
key str

Object key.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

open()

Perform connection routines when necessary.

Raises:

Type Description
BlobError

on error

parse_url(url) classmethod

Parse 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)

Store binary data under the given key.

If the key already exists, its value is overwritten.

Parameters:

Name Type Description Default
key str

Object key.

required
data bytes

Binary payload.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

scan(prefix)

Iterate all keys within prefix.

Parameters:

Name Type Description Default
prefix str

Prefix to scan.

required

Returns:

Type Description
Iterable[str]

Yields matched keys.

Raises:

Type Description
BlobError

On backend or I/O failure.