Skip to main content

# core-ftp

This project/library provides a comprehensive set of common components and interfaces designed to facilitate and streamline FTP connections, ensuring efficient communication and data transfer…


PyPI Downloads Python Versions License Pipeline Status Docs Status Security

Installation

Install from PyPI using pip:

pip install core-ftp
uv pip install core-ftp  # Or using UV...

Features

SFTP Client

  • Simplified SFTP connection management with context manager support

  • Multiple authentication methods:

    • Password-based authentication

    • SSH private key authentication with optional passphrase

    • Customizable transport and connection parameters

  • Comprehensive file operations:

    • List files and directories with detailed attributes

    • Upload files from local filesystem or file-like objects

    • Download files to local filesystem

    • Delete files and directories

    • Change and retrieve current working directory

  • Built-in error handling with custom exceptions

  • Automatic resource cleanup

ETL Support

  • Abstract base class for SFTP-based ETL tasks

  • Seamless integration with core-etl framework

  • File filtering capabilities:

    • Filter by file extension

    • Filter by filename prefix

    • Time-based filtering with delay options

  • Optional automatic file cleanup after successful processing

Examples

Password authentication

from core_ftp.clients.sftp import SftpClient, SftpConnectionConfig

config = SftpConnectionConfig(host="test.rebex.net", port=22, user="demo", password="password")

with SftpClient(config) as client:
    for name, attr in client.list_files("/"):
        print(name, attr)

SSH key authentication

from core_ftp.clients.sftp import SftpClient, SftpConnectionConfig

config = SftpConnectionConfig(host="localhost", port=23, user="foo", private_key_path="/path/to/id_rsa")

with SftpClient(config) as client:
    client.download_file("remote/file.txt", "/local/file.txt")

Upload a file

from core_ftp.clients.sftp import SftpClient, SftpConnectionConfig

config = SftpConnectionConfig(host="localhost", user="foo", password="pass")

with SftpClient(config) as client:
    client.chdir("/upload")
    client.upload_file("/local/report.csv", "report.csv", confirm=True)

ETL task (file-based processing)

from core_ftp.clients.sftp import SftpConnectionConfig
from core_ftp.etls.file_based import IBaseEtlFromFtpFile, SftpFileConfig

class DataProcessor(IBaseEtlFromFtpFile):
    @classmethod
    def registered_name(cls) -> str:
        return "DataProcessor"

    def process_file(self, path: str, **kwargs):
        print(f"Processing {path}")

DataProcessor(
    connection=SftpConnectionConfig(host="data.server.com", user="admin", password="secret"),
    file_config=SftpFileConfig(path="/data/csv", file_ext=".csv", delete_file_on_success=True),
).execute()

Local SFTP server using Docker

Functional tests require two local SFTP servers running via Docker (atmoz/sftp): one for password authentication (port 22) and one for SSH key authentication (port 23).

1. Password authentication (port 22)

docker run \
  --mount type=bind,source="$(pwd)/tests/resources/upload",target=/home/foo/upload \
  -p 22:22 -d atmoz/sftp foo:pass:::upload

2. SSH key authentication (port 23)

docker run \
  --mount type=bind,source="$(pwd)/tests/resources/ssh_keys/id_rsa.pub",target=/home/foo/.ssh/keys/id_rsa.pub,readonly \
  --mount type=bind,source="$(pwd)/tests/resources/upload",target=/home/foo/upload \
  -p 23:22 -d atmoz/sftp foo::1001

Run functional tests

python manager.py run-tests --test-type functional --pattern "*.py"

Quick Start

Installation

Install the package:

pip install core-ftp
uv pip install core-ftp     # Or using UV...
pip install -e ".[dev]"     # For development...

Setting Up Environment

  1. Install required libraries:

pip install --upgrade pip
pip install virtualenv
  1. Create Python virtual environment:

virtualenv --python=python3.12 .venv
  1. Activate the virtual environment:

source .venv/bin/activate

Install packages

pip install .
pip install -e ".[dev]"

Check tests and coverage

python manager.py run-tests
python manager.py run-coverage

Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Write tests for new functionality

  4. Ensure all tests pass: python manager.py run-tests

  5. Run linting: pylint core_ftp

  6. Run security checks: bandit -r core_ftp

  7. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

For questions or support, please open an issue on GitLab or contact the maintainers.

Authors

Metadata

Release files for core-ftp 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for core-ftp 3.1.1
File Size Uploaded
core_ftp-3.1.1.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for core-ftp 3.1.1
File Interpreter ABI Platform
core_ftp-3.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 28.7 kB

Release files / core_ftp-3.1.1.tar.gz

Download URL core_ftp-3.1.1.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7352c0ae78d1082df0214dc4b869b0e7c1ec7c62b232091b719368cb15da2ebf
BLAKE2b-256 checksum
How to use checksums
a86d72ba02357a1cbcc77cb369789eaa13f08cfaedcff5f6ac021105e1e5efff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / core_ftp-3.1.1-py3-none-any.whl

Download URL core_ftp-3.1.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7549e567cd6d5500481c610422c29dcec1bcd0187743018fbb71c341172a8a7c
BLAKE2b-256 checksum
How to use checksums
ca477f6c8158f8c3d3ae1ba7a904cc07ed14c5c2d3ae0a47852f8e753b44c904
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page