Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, warnings
- from ftplib import FTP
- def strInput(question):
- return input(question).strip('\r')
- running = "a"
- while running != "q":
- ## This section defines all necessary variables.
- btn = strInput("Enter Group BTN: ")
- devicename = strInput("Enter device BS name: ")
- model = strInput("Enter device model number (335, 450, 550, etc.): ")
- mac = strInput("Enter device MAC Address: ")
- first = strInput("Enter User First Name: ")
- last = strInput("Enter User Last Name: ")
- address = strInput("Enter User BS Address: ")
- label = strInput("Enter User Label: ")
- typ = strInput("Enter Line Type (private, shared): ")
- authid = strInput("Enter User Auth ID: ")
- authpw = strInput("Enter User Auth Password: ")
- ## Reads template file (BWDEVICE_template.cfg) to memory
- bwtf = open ("Z:/NOC/Test/BWDEVICE_template.cfg")
- var = bwtf.readlines()
- bwtf.close()
- ## Reads template file (template.cfg) to memory
- tf = open ("Z:/NOC/Test/template.cfg")
- var2 = tf.readlines()
- tf.close()
- ## Creates new file named BWDEVICE_%mac%.cfg
- bwnf = open("Z:/NOC/Test/BWDEVICE_"+mac+".cfg",'w')
- ## Writes to new file line by line, while replacing variables in template file with values
- for line in range(406):
- var[line] = var[line].replace("%First%", first)
- var[line] = var[line].replace("%Last%", last)
- var[line] = var[line].replace("%Address%", address)
- var[line] = var[line].replace("%Label%", label)
- var[line] = var[line].replace("%type%", typ)
- var[line] = var[line].replace("%authid%", authid)
- var[line] = var[line].replace("%authpw%", authpw)
- bwnf.write(var[line])
- ## Creates new file named %mac%.cfg
- nf = open("Z:/NOC/Test/"+mac+".cfg",'w')
- ## Writes to new file line by line, while replacing variables in template file with values
- for line2 in range(6):
- var2[line2] = var2[line2].replace("%devicename%", devicename)
- var2[line2] = var2[line2].replace("%mac%", mac)
- var2[line2] = var2[line2].replace("%model%", model)
- nf.write(var2[line2])
- bwnf.close()
- nf.close()
- ## Opens both newly created files as readable binaries
- bwf = open("Z:/NOC/Test/BWDEVICE_"+mac+".cfg",'rb')
- devf = open("Z:/NOC/Test/"+mac+".cfg",'rb')
- ## Connects to FTP
- ftp = FTP('204.11.148.130')
- ftp.debug(2)
- ftp.connect(timeout=100000)
- ftp.login(user=btn, passwd=btn)
- ## Stores both files to FTP
- ftp.storbinary('STOR BWDEVICE_'+mac+'.cfg', bwf)
- ftp.storbinary('STOR '+mac+'.cfg', devf)
- ## Closes files
- bwf.close()
- devf.close()
- ## Disconnects from FTP Server
- ftp.close()
- ## Self-explanatory.
- running = input("Press 'Q' to quit.\n")
Add Comment
Please, Sign In to add comment