Registry / devops / genie-libs-filetransferutils

genie-libs-filetransferutils

JSON →
library26.5pypypiunverified

Genie-libs FileTransferUtils provides a set of utilities for managing file transfers to and from network devices within the Cisco Genie automation framework. It simplifies operations like preparing a device for transfer, initiating file uploads/downloads, and verifying file integrity. The current version is 26.3, and it follows the release cadence of the broader Genie/pyATS ecosystem, typically with frequent updates aligned with new Genie releases.

pip install genie-libs-filetransferutils
INSTALL
IMPORT
SIG · GENIE-LIBS-FILETRA
G
genie-libs-filetransferutils
devopspythonv26.5
Install
6.8s avg
Import
Disk
57MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v26.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 97.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 6.8s · import 0.000s · 68MB
57MB installed
● package 57MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FileTransferUtils
from genie.libs.filetransferutils import FileTransferUtils
from genie.libs.filetransferutils import FileTransferUtils

This quickstart demonstrates how to use `FileTransferUtils` to prepare and execute a file transfer to a network device. It uses `unittest.mock.MagicMock` to simulate a `device` object from a pyATS testbed, allowing the code to run without a live network setup. In a real scenario, the `device` object would be obtained from a loaded pyATS testbed (`pyats.topology.loader`).

import os from unittest.mock import MagicMock from genie.libs.filetransferutils.filetransferutils import FileTransferUtils # Mock a device object for demonstration purposes # In a real scenario, this 'device' object would come # from a loaded pyATS testbed (e.g., testbed.devices['my_device']) mock_device = MagicMock() mock_device.name = "mock_device_nxos1" mock_device.connections.cli.connection_args = {'protocol': 'ssh'} mock_device.os = 'nxos' # Mock FileTransferUtils methods that would interact with a real device mock_file_transfer_obj = MagicMock() mock_file_transfer_obj.transfer.return_value = True # Simulate successful transfer mock_file_transfer_obj.get_file_size.return_value = 1024 # Simulate file size check mock_device.api.get_file_transfer_obj.return_value = mock_file_transfer_obj # Create a dummy local file for transfer simulation local_file_path = "local_dummy_file.txt" with open(local_file_path, "w") as f: f.write("This is a dummy file for transfer simulation.") try: # Initialize FileTransferUtils with the device object file_transfer = FileTransferUtils(device=mock_device) # Define remote path for the transfer remote_path = "/bootflash/dummy_file_on_device.txt" # Prepare for file transfer (e.g., check space, permissions on the device) # The 'prepare_transfer' method returns a dictionary of transfer details transfer_info = file_transfer.prepare_transfer( source_path=local_file_path, destination_path=remote_path, method="scp", # Common transfer methods: scp, tftp, ftp overwrite=True ) print(f"Prepared transfer for device {mock_device.name}: {transfer_info}") # Perform the actual file transfer to the device success = file_transfer.transfer( source_path=local_file_path, destination_path=remote_path, method="scp", overwrite=True ) if success: print(f"File '{local_file_path}' successfully transferred to '{remote_path}' on {mock_device.name}") # Example: Get remote file size (mocked interaction) remote_file_size = file_transfer.get_file_size(path=remote_path, method="scp") print(f"Remote file size: {remote_file_size} bytes") else: print("File transfer failed.") except Exception as e: print(f"An error occurred: {e}") finally: # Clean up the dummy file if os.path.exists(local_file_path): os.remove(local_file_path)
Debug
Known issues
gotchaFileTransferUtils relies heavily on a properly initialized `device` object from a pyATS testbed. If the `device` object is `None` or lacks necessary attributes (e.g., `os`, `connections`), methods will fail.
fix
Ensure your pyATS testbed is correctly loaded and you are passing a valid, active `Device` object (e.g., `testbed.devices['my_device']`) to the `FileTransferUtils` constructor.
affects: All versions
gotchaVersion mismatches between `genie-libs-filetransferutils` and other core `genie` or `pyats` packages can lead to unexpected `AttributeError` or import failures, as the ecosystem is tightly integrated.
fix
Always install `genie` and all `genie.libs` packages from the same release train. It's recommended to install `pyats` and `genie` first, then specific `genie.libs` packages. Use `pip install --upgrade pyats genie genie.libs.filetransferutils` to ensure consistency.
affects: All versions
gotchaWhen performing file transfers, ensure both the local source file exists and the remote destination path on the device is valid and has sufficient permissions/space. Common issues include `FileNotFoundError` (for local source) or device-side errors (permissions, invalid path) reported by the transfer method.
fix
Verify local file existence with `os.path.exists()`. For remote paths, consult device documentation for valid file systems and paths. Ensure the user credentials used for device connection have appropriate read/write permissions for the transfer method (e.g., SCP/SFTP credentials for 'scp').
affects: All versions
Upgrade
Version history
26.5latest on PyPI · released May 28, 2026
Audit
Dependencies
genierequiredThis library is a component of the Genie automation framework and requires core Genie packages (which often include pyats) to function, especially for device interaction and testbed loading.
Agent activity
12 hits · last 30 days
node
12
Resources
genie-libs-filetransferutils — pip install genie-libs-filetransferutils · libregistry