<br>Here is my script:<br><br>send_file.py<br><br><br>import os, random, re, string, sys, telnetlib, threading, time<br>from time import strftime<br>from threading import Thread<br><br><br>class ConfigIT(threading.Thread):
<br>&nbsp;&nbsp;&nbsp; def __init__(self,host):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Thread.__init__(self)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.host = host<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.filename = filename<br><br>&nbsp;&nbsp;&nbsp; def run(self):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn = telnetlib.Telnet(self.host)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;Username: &quot;, 7)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; except:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host + &quot; - not responding.\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.flush()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(user + &quot;\n&quot;)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;Password: &quot;, 7)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(pswd + &quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (index, match, read) = tn.expect([&quot;#&quot;], 7)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if not match:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host
 + &quot; - sign-on failure.\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.flush()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;conf t\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rpath = (dirPath + &quot;\\&quot; + self.filename)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print rpath<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; input = file(rpath, &quot;r&quot;)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for line in file(rpath):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; text = input.readline()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(text)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (index, match, read) = tn.expect([&quot;%&quot;], 1)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if match:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host + &quot; - config error on line = &quot; + text)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.flush()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;end\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
tn.read_until(self.host.upper() + &quot;#&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br># write config to NVRAM<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;wr\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(self.host.upper() + &quot;#&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
time.sleep(random.uniform(0,2))<br># write config to TFTP<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;wr net\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;]?&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;192.168.19.201\n
&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;]?&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;[confirm]&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (index, match, read) = tn.expect([&quot;OK&quot;], 15)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if &quot;Error opening tftp&quot; in read:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host + &quot; - config write net failed.\n&quot;)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.flush()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br># if host = *swa, then write vlan.dat to SYSMAN<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m = match_swa.match(self.host)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if m:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;copy flash tftp\n&quot;)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;]? &quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;vlan.dat\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;]? &quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform
(0,2))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;192.168.19.201\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;dat]? &quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(random.uniform(0,2))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(self.host + &quot;.vlan.dat\n&quot;)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (index, match, read) = tn.expect([&quot;OK&quot;], 15)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if &quot;Error opening tftp&quot; in read:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host + &quot; - VLAN write net failed.\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
output.flush()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;exit\n&quot;)<br><br>def count_active():<br>&nbsp;&nbsp;&nbsp; &quot;&quot;&quot; returns the number of Getter threads that are alive &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp; num_active = 0
<br>&nbsp;&nbsp;&nbsp; for thread in tlist:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if thread.isAlive():<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num_active += 1<br>&nbsp;&nbsp;&nbsp; return num_active<br><br>threads = []<br>dirPath = (r&quot;c:\temp\config&quot;)<br>dirList = os.listdir(dirPath)<br>match_swa = 
re.compile('^s\d\d\d\d[s][w][a]')<br>Max_Threads = 10<br>pswd = &quot;Activ8&quot;<br>tlist = []<br>user = &quot;cworks&quot;<br>logFile = (r&quot;c:\logs\send_file.log&quot;)<br>output = file(logFile, &quot;a&quot;)<br>output.write
(&quot;\n&quot; + &quot;send_file script started -&quot; + strftime(&quot; %H:%M:%S %x&quot;) + &quot;\n&quot;)<br>output.flush()<br><br>for file in dirList:<br>&nbsp;&nbsp;&nbsp; filename = file.lower()<br>&nbsp;&nbsp;&nbsp; host = filename.replace('.txt', '')
<br>&nbsp;&nbsp;&nbsp; while count_active() &gt;= Max_Threads:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; time.sleep(1)<br>&nbsp;&nbsp;&nbsp; threads = ConfigIT(host)<br>&nbsp;&nbsp;&nbsp; tlist.append(threads)<br>&nbsp;&nbsp;&nbsp; threads.start()<br><br>for thread in tlist:<br>&nbsp;&nbsp;&nbsp; thread.join()<br><br>output.write
(&quot;send_file script completed -&quot; + strftime(&quot; %H:%M:%S %x&quot;) + &quot;\n&quot;)<br>output.flush()<br>output.close()<br><br><br><span style="color: rgb(255, 0, 0); font-weight: bold;">Here is the error:</span>
<br style="color: rgb(255, 0, 0); font-weight: bold;"><br style="color: rgb(255, 0, 0); font-weight: bold;">&gt;pythonw -u &quot;send_file.py&quot;<br>c:\temp\config\rtr0544.txt<br>Exception in thread Thread-1:<br>Traceback (most recent call last):
<br>&nbsp; File &quot;c:\python24\lib\threading.py&quot;, line 442, in __bootstrap<br>&nbsp;&nbsp;&nbsp; self.run()<br>&nbsp; File &quot;send_file.py&quot;, line 45, in run<br>&nbsp;&nbsp;&nbsp; input = file(rpath, &quot;r&quot;)<br>TypeError: 'str' object is not callable
<br><br>&gt;Exit code: 0<br><br><br><br><br>The above script was created using the following script:<br><br>send_file.r1.py<br><br>#<br># This script obtains a directory listing, strips the extensions and telnets to the<br>
# device (which is the filename in the directory). Then it writes the commands in the<br># file to the device, saves config and writes it back to SYSMAN. It can be run using:<br>#&nbsp;&nbsp;&nbsp; python send_file.py<br>#<br># Note: &quot;os&quot; is imported for future functionality.
<br>#<br># by: TCDH<br># on: 10/17/05<br># revised: 10/18/05&nbsp;&nbsp;&nbsp; TCDH - Added logic to check for offline devices and sign-on failures.<br>#<br><br>import os, re, string, sys, telnetlib, threading, time<br>from time import strftime
<br>from threading import Thread<br><br>dirPath = (r&quot;c:\temp\config&quot;)<br>dirList = os.listdir(dirPath)<br>pswd = &quot;Activ8&quot;<br>user = &quot;cworks&quot;<br>logFile = (r&quot;c:\logs\send_file.log&quot;)<br>
output = file(logFile, &quot;a&quot;)<br>output.write(&quot;\n&quot; + &quot;send_file script started -&quot; + strftime(&quot; %H:%M:%S %x&quot;) + &quot;\n&quot;)<br>output.flush()<br><br>class ConfigIT(threading.Thread
):<br>&nbsp;&nbsp;&nbsp; def __init__(self,host):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Thread.__init__(self)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.host = host<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.filename = filename<br><br>&nbsp;&nbsp;&nbsp; def run(self):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn = telnetlib.Telnet(self.host)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;Username: &quot;, 7)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; except:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host + &quot;: not responding.\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(user + &quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
tn.read_until(&quot;Password: &quot;, 7)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(pswd + &quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (index, match, read) = tn.expect([&quot;#&quot;], 7)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if not match:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write(self.host + &quot;: sign-on failure.\n&quot;)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;conf t\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rpath = (dirPath + &quot;\\&quot; + self.filename)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print rpath<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; input = file(rpath, &quot;r&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for line in file(rpath):
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(input.readline())<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;end\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(self.host.upper() + &quot;#&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;wr\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(self.host.upper() + &quot;#&quot;)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;wr net\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;host []?&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;192.168.19.201\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;confg]? &quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;\n&quot;)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.read_until(&quot;[confirm]&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (index, match, read) = tn.expect([&quot;OK&quot;], 15)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if &quot;Error opening tftp&quot; in read:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output.write
(self.host + &quot;: write net failed.\n&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tn.write(&quot;exit\n&quot;)<br><br>tlist = []<br><br>for host in dirList:<br>&nbsp;&nbsp;&nbsp; filename = host.lower()<br>&nbsp;&nbsp;&nbsp; host = host.lower()<br>&nbsp;&nbsp;&nbsp; host = 
host.replace('.txt', '')<br>&nbsp;&nbsp;&nbsp; current = ConfigIT(host)<br>&nbsp;&nbsp;&nbsp; tlist.append(current)<br>&nbsp;&nbsp;&nbsp; current.start()<br><br>for entry in tlist:<br>&nbsp;&nbsp;&nbsp; entry.join()<br><br>output.write(&quot;send_file script completed -&quot; + strftime(&quot; %H:%M:%S %x&quot;) + &quot;\n&quot;)
<br>output.flush()<br>output.close()<br><br><br>They both use the same syntax to open the input file, however only send_file.py receives an error. What gives?<br><br><br>