Remote Operations
The remote operations module provides utilities for working with remote systems, SSH connections, and remote file operations.
Module Overview
Modern remote file operations for siege_utilities. Provides clean, type-safe file download utilities.
- siege_utilities.files.remote.download_file(url, local_filename, chunk_size=8192, timeout=30, verify_ssl=True)[source]
Download a file from a URL to a local file with progress bar.
SECURITY: Validates local file path to prevent path traversal attacks.
- Parameters:
- Returns:
The local filename as a string
- Raises:
PathSecurityError – If local path fails security validation
ConnectionError – If HTTP request fails (non-2xx status)
requests.exceptions.Timeout – If request times out
requests.exceptions.RequestException – If request fails
OSError – If file write fails
- Return type:
Example
>>> result = download_file("https://example.com/file.zip", "downloads/file.zip") >>> print(f"Downloaded to {result}")
- siege_utilities.files.remote.generate_local_path_from_url(url, directory_path, as_string=True)[source]
Generate a local file path from a URL.
SECURITY: Validates directory path to prevent path traversal attacks.
- Parameters:
- Returns:
Path object or string
- Raises:
ValueError – If filename cannot be extracted from URL
PathSecurityError – If directory path fails security validation
OSError – If directory creation fails
- Return type:
Example
>>> path = generate_local_path_from_url("https://example.com/file.zip", "downloads") >>> print(f"Local path: {path}")
- siege_utilities.files.remote.download_file_with_retry(url, local_filename, max_retries=3, retry_delay=5, **kwargs)[source]
Download a file with automatic retry on failure.
- Parameters:
- Returns:
The local filename as a string
- Raises:
ConnectionError – If all retry attempts fail
requests.exceptions.RequestException – If all retry attempts fail
- Return type:
Example
>>> result = download_file_with_retry("https://example.com/file.zip", "file.zip") >>> print(f"Downloaded to {result}")
- siege_utilities.files.remote.get_file_info(url, timeout=10)[source]
Get information about a remote file without downloading it.
- Parameters:
- Returns:
Dictionary with file information
- Raises:
ConnectionError – If HTTP request fails (non-2xx status)
requests.exceptions.RequestException – If request fails
ImportError – If requests library is not available
- Return type:
Example
>>> info = get_file_info("https://example.com/file.zip") >>> print(f"File size: {info['size']} bytes")
- siege_utilities.files.remote.is_downloadable(url, timeout=10)[source]
Check if a URL points to a downloadable file.
- Parameters:
- Returns:
True if the URL points to a downloadable file, False otherwise
- Return type:
Example
>>> if is_downloadable("https://example.com/file.zip"): ... print("URL is downloadable")
Functions
Usage Examples
Basic SSH connection:
Remote command execution:
File operations:
Batch operations:
Unit Tests
The remote operations module has comprehensive test coverage:
Test Results: All remote operation tests pass successfully with comprehensive coverage.