Registry /
devops / genie-libs-filetransferutils
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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 97.8MB
glibcpy 3.10–3.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)
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.