cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1491
Views
0
Helpful
8
Replies

Uploading a File to ISR4321/K9 via Perl Script Using TFTP

HUSEYIN VAROGLU
Level 1
Level 1

Hi!

I'm trying to opload a config file with txt extension to a ISR4321/K9 and router TFTP debug "TFTP: Sending error 2 Access denied". Is this is possible?

 

001392: Mar 4 10:09:22: TFTP: Server request for port 54576, socket_id 0x7FA143143B30 for process 424
001393: Mar 4 10:09:22: TFTP: write request from host 192.168.240.3(54576) via GigabitEthernet0/0/1.300
001394: Mar 4 10:09:22: TFTP: Sending error 2 Access denied

8 Replies 8

balaji.bandi
Hall of Fame
Hall of Fame

What TFTP Server is this, Do you have permission to write files into the folder?

 

what is the outcome if you do it manually? with out any scripting? is that works?

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

I can do it manually on the router by the "copy tftp: flash" command and i have to do this about 2100 router one by one. So, I want to do this by Perl code. Is the permission you ask for router or local?

just to confirm you able to manually use TFT and copy the files - it is a success there is no access issue.

 

can you share the Perl script to look or enable debug in the Perl code to see what step this getting error ?

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Perl script i code is below. There is no debug code for the TFTP module. get method is successful but put method is not.. 

The documentation for Perl TFTP module : https://metacpan.org/pod/release/GSM/TFTP-1.0b3/TFTP.pm

 

Code:

#!/usr/bin/perl

use TFTP;
use strict;
use warnings;

$tftp = new TFTP("10.205.80.1");
#$tftp->get("DCCO-OPERASYON-MPLS.txt", "Z:/Miscellaneous/BACKUPs/ALT-AEM/DCCO-OPERASYON-MPLS-startup.txt");
$tftp->octet;
$tftp->put("Z:/Miscellaneous/BACKUPs/ALT-AEM/SAMSUN-660-MPLS.txt", "bootflash:/SAMSUN-660-MPLS.txt");
$tftp->quit;

I did litle changes in the code for perl and it is below. 

#!/usr/bin/perl

use TFTP;
use strict;
use warnings;

my $tftp;

$tftp = new TFTP("10.205.80.1") || die;
#$tftp->get("DCCO-OPERASYON-MPLS.txt", "Z:/Miscellaneous/BACKUPs/ALT-AEM/DCCO-OPERASYON-MPLS-startup.txt");
#$tftp->octet;
$tftp->put("Z:/Miscellaneous/BACKUPs/ALT-AEM/SAMSUN-660-MPLS.txt", "bootflash:/SAMSUN-660-MPLS.txt") || die;
$tftp->quit;

 

Output after running my script:

Z:\PERL>perl tftp-test2.pl
Died at tftp-test2.pl line 12.

Z:\PERL>

Trying to understand your Logic - is there any code i missing here? (this is the code ?)

 

here are the process :

 

1. the script first log in to switch (with the switch credentials)

2. from the switch you need to initiate the copy process.

3. you may ask to enter yes or y (this is expected command you need to parse)

4. you capture the process success or not by checking the file in flash or not

5. then end the script, write output to the file the device completed. and move to the next device, if that fails, report back failed device.

 

use the below guide : (this is for telnet) you can replace with SSH for security.

 

https://metacpan.org/pod/Net::Telnet::Cisco

 

This is another guide (which using copy from device to TFTP, you can use another way from TFTP to switch

 

https://www.perlmonks.org/?node_id=864948

 

the easy way is: get cat tools for 14 days trail all it does for you :

 

https://www.solarwinds.com/kiwi-cattools

 

 

 

 

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

 

First of all, thank you very much for your interest and support.

 

I just wanted to know: Can a file be uploaded directly to a Cisco device with software containing the tftp code? Or is it possible to connect to a cisco device with ssh first and then pull the file over it with the tftp command? So is it absolutely necessary to make a ssh connection to the device?

 

My point is to improve myself on other topics that will be useful to my job besides the main work I do. Especially about software ..

 

If you give me time I will work on the code in the link https://www.perlmonks.org/?node_id=864948 and reply as soon as possible.

 

Thank you very much again and again

I just wanted to know: Can a file be uploaded directly to a Cisco device with software containing the tftp code? Or is it possible to connect to a cisco device with ssh first and then pull the file over it with the tftp command? So is it absolutely necessary to make a ssh connection to the device?

Not sure if i understand this correctly,   what TFTP code. ?

 

 it all depends on the requirement, you can connect the device and pull the file from TFTP. ( you need to have some form of connection to the device to update the information you intend to do right?

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Review Cisco Networking for a $25 gift card