# Cisco tftp upload via snmpset

**URL:** <https://www.ruby-forum.com/t/cisco-tftp-upload-via-snmpset/143915>\
**Category:** Ruby\
**Created:** [July 23, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/cisco-tftp-upload-via-snmpset/143915 "2008-07-23T20:47:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![heinrich1208](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@heinrich1208](https://www.ruby-forum.com/u/heinrich1208)\
**Post date:** [July 23, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/cisco-tftp-upload-via-snmpset/143915/1 "2008-07-23T20:47:24Z")

</div>

Hi all,

whoever is interested in it.

#!/usr/bin/ruby  
#Version 0.1 Heinrich P. - basic version of  
snmpset-copy-running-config-to-tftp.rb

require ‘yaml’  
require ‘snmp’  
require ‘socket’  
#require ‘daemons’  
#require ‘action\_mailer’  
require ‘csv’  
include Socket::Constants  
#include Daemonize

# Cisco OIDs (variables)

#The ConfigCopyProtocol is set to TFTP  
oid\_setTFTP = “1.3.6.1.4.1.9.9.96.1.1.1.1.2.111 i 1”  
#Set the SourceFileType to running-config  
oid\_setRUNNINGCONFIG = “1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4”  
#Set the DestinationFileType to networkfile  
oid\_setDSTFILENETWORK = “1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 1”  
#Sets the ServerAddress to the IP address of the TFTP server  
1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a   
oid\_setIPADDRTFTPSERVER = “1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a”  
#Sets the CopyFilename to your desired file name  
1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s   
oid\_setDSTFILENAME = “1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s”  
#Sets the CopyStatus to active which starts the copy process  
1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1  
oid\_setSTARTPROCESS = “1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1”  
#[idcnetwatch1.bxc.is-teledata.com](http://idcnetwatch1.bxc.is-teledata.com) (TFTP server)  
tftpserver = ‘172.29.0.254’  
#hostlist including all switches  
hostlist =  
‘/homes/network-monitoring/snmpset-copy-running-config-to-tftp.conf’  
#snmp RO  
rocommunity = ‘public’  
#snmp RW  
rwcommunity = ‘secret’

#start logic

#check if configfile is available  
if ((File.exist?(hostlist)) && (File.readable?(hostlist)))  
host = CSV.readlines(hostlist)  
else  
puts ‘Cannot locate configuration file! Please check!’  
exit  
end

host.each do |ip|  
system('snmpset -v2c -c ’ + “#{rwcommunity} #{ip} #{oid\_setTFTP}”)  
system('snmpset -v2c -c ’ + “#{rwcommunity} #{ip}  
#{oid\_setRUNNINGCONFIG}” )  
system('snmpset -v2c -c ’ + “#{rwcommunity} #{ip}  
#{oid\_setDSTFILENETWORK}” )  
system('snmpset -v2c -c ’ + “#{rwcommunity} #{ip}  
#{oid\_setIPADDRTFTPSERVER} #{tftpserver}” )  
system('snmpset -v2c -c ’ + “#{rwcommunity} #{ip}  
#{oid\_setDSTFILENAME} #{ip}” )  
system('snmpset -v2c -c ’ + “#{rwcommunity} #{ip}  
#{oid\_setSTARTPROCESS}” )  
end
