cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
148
Views
0
Helpful
1
Replies

PyATS: How to transfer a file using PyATS?

assadniang
Level 1
Level 1

Hello,

Is there any documentation or example on how to tranfer a file using PyATS?

I search online, and this came up on google, but when I tried to run in with PyATS ver 23, it said cannot find fileops :

 

import pyats
from pyats.utils import fileops

# Create a Testbed object
testbed = pyats.Testbed()

# Add a device to the Testbed
device = testbed.devices.add(
    name="my_device",
    os="ios",
    connections={
        "console": {
            "protocol": "netmiko",
            "ip": "192.168.1.1",
            "username": "cisco",
            "password": "cisco",
        }
    },
)

# Define the source and destination file paths
source_file = "/path/to/source/file"
destination_file = "/path/to/destination/file"

# Create a callback function to track the progress of the transfer
def progress_callback(filename, bytes_transferred, total_bytes):
    print("Transferred {} bytes of {} bytes".format(bytes_transferred, total_bytes))

# Transfer the file
fileops.transfer_file(
    device=device,
    source_file=source_file,
    destination_file=destination_file,
    progress_callback=progress_callback,
)

 

This given by copilot didn't work either, scp not found:

from pyats.topology import loader

# Load the testbed file
testbed = loader.load('path_to_your_testbed_file.yaml')

# Select the device
device = testbed.devices['your_device_name']

# Connect to the device
device.connect()

# Transfer the file
device.scp(source='server:/path/to/file', destination='/path/on/device')

 

1 Reply 1

Marcel Zehnder
Spotlight
Spotlight

Hi, I never tried/used it, but found this in the doc, maybe it helps:https://pubhub.devnetcloud.com/media/pyats/docs/utilities/file_transfer_server.html