01-19-2026 03:40 AM - edited 01-19-2026 03:41 AM
> python3 .\CiscoTFTPBackupNexusTestedOK.py
******************************************************************************
Password:
192.168.3.71 is up
192.168.3.72 is up
**** Enter TFTP server IP addr **** :- 192.168.0.26
******************************************************************************
Connecting to the IP/Device... 192.168.3.71
Successfully Connected to.... DC01-NX-BL-71
******************************************************************************
Connecting to the IP/Device... 192.168.3.72
Successfully Connected to.... DC01-NX-BL02-72
******************************************************************************
Backup Completed Successfully....
******************************************************************************
Directly from device it is working fine.
DC01-NX-BL-71(config-line)# copy running-config tftp: vrf management
Enter destination filename: [DC01-NX-BL-71-running-config]
Enter hostname for the tftp server: 192.168.0.26
Trying to connect to tftp server......
Connection to Server Established.
TFTP put operation was successful
01-19-2026 11:08 PM - edited 01-19-2026 11:42 PM
Hi @uni1389
If your pasted output is correct, it looks like your script never hits the if-statements after the copy command. Can you add some "debug-prints" to verify and paste the output:
from datetime import datetime
from getpass import getpass
from netmiko import ConnectHandler
import time
import os
today = str(datetime.now().strftime('%d%m%Y%H%M'))
filename = (today + "_Switch.txt")
print('******************************************************************************')
password = getpass()
ipaddrs = ["192.168.3.71","192.168.3.72"]
devices = [
{
"device_type": "cisco_nxos",
"host": ip,
"username": "admin",
'password': 'cisco',
'port' : 22, # optional, defaults to 22
'secret': 'cisco',
}
for ip in ipaddrs
]
for ip in ipaddrs:
response = os.popen('ping ' + ip).read()
if 'Received = 4' in response:
print(ip, 'is up')
else:
print(ip, 'is down')
tftp = input('**** Enter TFTP server IP addr **** :- ')
for device in devices:
print('******************************************************************************\n')
print(f'Connecting to the IP/Device... {device["host"]}')
net_connect = ConnectHandler(**device)
gethostname= net_connect.send_command('sh run | i host').split()[1]
showint = net_connect.send_command('show int mgmt0 | inc Internet')
showver = net_connect.send_command('show version | inc .bin')
print("Successfully Connected to.... "+gethostname)
filename = (gethostname+ ".txt")
copy_cmd = "copy running-config tftp: vrf management"
net_connect.enable()
time.sleep(1)
output1 = net_connect.send_command_timing(copy_cmd)
print(output1)
if 'Source filename' in output1:
output1 += net_connect.send_command_timing('\n')
print(output1)
if 'remote host' in output1:
output1 += net_connect.send_command_timing(tftp)
print(output1)
if 'Destination filename' in output1:
output1 += net_connect.send_command_timing(filename)
print(output1)
print (output1)
print('******************************************************************************\n')
print('Backup Completed Successfully....')
print('*
If you don't see the expected ouput, you may need to tweak your commands and make sure to include the prompts:
output1 = net_connect.send_command_timing(copy_cmd, strip_prompt=False, strip_command=False)
print(output1)
if 'Source filename' in output1:
output1 += net_connect.send_command_timing('\n', strip_prompt=False, strip_command=False)
print(output1)
if 'remote host' in output1:
output1 += net_connect.send_command_timing(tftp, strip_prompt=False, strip_command=False)
print(output1)
if 'Destination filename' in output1:
output1 += net_connect.send_command_timing(filename, strip_prompt=False, strip_command=False)
print(output1)
print (output1)
PS: If copy via SCP is an option for you, check out Netmikos secure copy support, it might be easier: https://pynet.twb-tech.com/blog/expanding-netmiko-secure-copy-support.html
01-20-2026 12:23 AM
i use below both EEM and Python check :
https://www.balajibandi.com/?p=717
https://www.balajibandi.com/?p=1437
=====Preenayamo Vasudevam=====
***** Rate All Helpful Responses *****
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide