Guest User

Untitled

a guest
Oct 22nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. import sys, warnings
  2. from ftplib import FTP
  3.  
  4. def strInput(question):
  5. return input(question).strip('\r')
  6.  
  7. running = "a"
  8. while running != "q":
  9.  
  10. ## This section defines all necessary variables.
  11. btn = strInput("Enter Group BTN: ")
  12. devicename = strInput("Enter device BS name: ")
  13. model = strInput("Enter device model number (335, 450, 550, etc.): ")
  14. mac = strInput("Enter device MAC Address: ")
  15. first = strInput("Enter User First Name: ")
  16. last = strInput("Enter User Last Name: ")
  17. address = strInput("Enter User BS Address: ")
  18. label = strInput("Enter User Label: ")
  19. typ = strInput("Enter Line Type (private, shared): ")
  20. authid = strInput("Enter User Auth ID: ")
  21. authpw = strInput("Enter User Auth Password: ")
  22.  
  23.  
  24. ## Reads template file (BWDEVICE_template.cfg) to memory
  25. bwtf = open ("Z:/NOC/Test/BWDEVICE_template.cfg")
  26. var = bwtf.readlines()
  27. bwtf.close()
  28.  
  29. ## Reads template file (template.cfg) to memory
  30. tf = open ("Z:/NOC/Test/template.cfg")
  31. var2 = tf.readlines()
  32. tf.close()
  33.  
  34. ## Creates new file named BWDEVICE_%mac%.cfg
  35. bwnf = open("Z:/NOC/Test/BWDEVICE_"+mac+".cfg",'w')
  36.  
  37. ## Writes to new file line by line, while replacing variables in template file with values
  38. for line in range(406):
  39. var[line] = var[line].replace("%First%", first)
  40. var[line] = var[line].replace("%Last%", last)
  41. var[line] = var[line].replace("%Address%", address)
  42. var[line] = var[line].replace("%Label%", label)
  43. var[line] = var[line].replace("%type%", typ)
  44. var[line] = var[line].replace("%authid%", authid)
  45. var[line] = var[line].replace("%authpw%", authpw)
  46. bwnf.write(var[line])
  47. ## Creates new file named %mac%.cfg
  48. nf = open("Z:/NOC/Test/"+mac+".cfg",'w')
  49.  
  50. ## Writes to new file line by line, while replacing variables in template file with values
  51. for line2 in range(6):
  52. var2[line2] = var2[line2].replace("%devicename%", devicename)
  53. var2[line2] = var2[line2].replace("%mac%", mac)
  54. var2[line2] = var2[line2].replace("%model%", model)
  55. nf.write(var2[line2])
  56. bwnf.close()
  57. nf.close()
  58.  
  59. ## Opens both newly created files as readable binaries
  60. bwf = open("Z:/NOC/Test/BWDEVICE_"+mac+".cfg",'rb')
  61. devf = open("Z:/NOC/Test/"+mac+".cfg",'rb')
  62.  
  63. ## Connects to FTP
  64. ftp = FTP('204.11.148.130')
  65. ftp.debug(2)
  66. ftp.connect(timeout=100000)
  67. ftp.login(user=btn, passwd=btn)
  68.  
  69. ## Stores both files to FTP
  70. ftp.storbinary('STOR BWDEVICE_'+mac+'.cfg', bwf)
  71. ftp.storbinary('STOR '+mac+'.cfg', devf)
  72.  
  73. ## Closes files
  74. bwf.close()
  75. devf.close()
  76.  
  77. ## Disconnects from FTP Server
  78. ftp.close()
  79.  
  80. ## Self-explanatory.
  81. running = input("Press 'Q' to quit.\n")
Add Comment
Please, Sign In to add comment