05-23-2023 02:13 AM - edited 05-23-2023 02:17 AM
I want to save the startup-config to TFTP server with the class .save_config in netmiko but when i call it the server not respone. Of course I try by CLI on router : copy startup-config tftp://10.64.0.146 it works. The code is SSH to Router OK
This is output:
R1941#
10.64.0.146
Trying 10.64.0.146 ...
% Connection refused by remote host
This is my code:
net_connect = ConnectHandler(**router)
net_connect.enable()
promt = net_connect.find_prompt()
print(promt)
tftp_server = '10.64.0.146'
name_cfg = str('Router_' + date_backup + '_config')
output = net_connect.save_config (tftp_server, name_cfg + '.txt')
net_connect.disconnect()
Thank you!
05-23-2023 02:34 AM
Can you check on the TFTP side and see what incoming IP is seen and port?
05-23-2023 02:45 AM
I try by the CLI the command R1941#copy startup-config tftp://10.64.0.146/, and it work, i can backup startup-config
05-23-2023 03:19 AM - edited 05-23-2023 03:20 AM
Hi
Where in your code you are saying this is a tftp call?
On the command line when you add tftp:// the IOS knows that this tcp port 69. But, looking the code, I did not see any reference to the protocol only the IP address.
05-23-2023 05:38 AM
Hello @kevintrankevin18241;
The problem lies in the incorrect usage of the "save_config" method in Netmiko. The "save_config" method is used to save the running configuration of the device to the startup configuration, not to backup the configuration to a TFTP server.
Try with this command "send_command()"
net_connect = ConnectHandler(**router)
net_connect.enable()
tftp_server = '10.64.0.146'
name_cfg = 'Router_' + date_backup + '_config'
command = f'copy startup-config tftp://{tftp_server}/{name_cfg}.txt'
output = net_connect.send_command(command)
net_connect.disconnect()
05-23-2023 06:13 PM
Agree with you, I try this class with default information and the code run with the "write mem" command. I try another way by the code:
net_connect.send_command_timing(config_commands)
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