@@ -20,34 +20,48 @@ def __init__(self, tgt_address, username= "admin", password= ""):
2020 self .user = username
2121 self .pwd = password
2222 self .FTP = FtpHelper (tgt_address , username , password )
23+ self .SCP = ScpHelper (tgt_address , username , password )
2324 self .ini_parser = ConfigParser ()
25+ self .__9603 = False
2426
2527 def retrieve_file (self , tgt_file : str , dest : str ):
26- #First try the FTP, if this fails to connect use SCP
27- try :
28- local_copy = self .FTP .get_file (tgt_file , dest )
29- except :
30- #if error from FTP, use SCP via SSH
28+ if (self .__9603 ):
3129 #fix the path to ni-rt.ini if ni-rt linux is target
32- print ("Could not connect to target via FTP, using SCP" )
3330 if ("ni-rt.ini" in tgt_file ):
34- tgt_file = "/etc/natinst/share/ni-rt.ini"
35- with ScpHelper (self .ip_address , self .user , self .pwd ) as s :
36- local_copy = s .get_file (tgt_file , dest )
37- finally :
38- return local_copy
31+ tgt_file = "/etc/natinst/share/ni-rt.ini"
32+ local_copy = self .SCP .get_file (tgt_file , dest )
33+ else :
34+ #Try the FTP, if this fails to connect use SCP
35+ try :
36+ local_copy = self .FTP .get_file (tgt_file , dest )
37+ except :
38+ #if error from FTP, use SCP via SSH
39+ print ("Could not connect to target via FTP, using SCP" )
40+ self .__9603 = True
41+ if ("ni-rt.ini" in tgt_file ):
42+ tgt_file = "/etc/natinst/share/ni-rt.ini"
43+ local_copy = self .SCP .get_file (tgt_file , dest )
44+
45+ return local_copy
46+
3947
4048 def send_file (self , tgt , dest_path ):
41- #First try the FTP, if this fails to connect use SCP
42- try :
43- self .FTP .upload_file (tgt , dest_path )
44- except :
45- #if error from FTP, use SCP via SSH
49+ if (self .__9603 ):
4650 #fix the path to ni-rt.ini if ni-rt linux is target
47- if ("ni-rt.ini" in dest_path ):
48- dest_path = "/etc/natinst/share/ni-rt.ini"
49- with ScpHelper (self .ip_address , self .user , self .pwd ) as s :
50- s .upload_file (tgt , dest_path )
51+ if ("ni-rt.ini" in dest_path ):
52+ dest_path = "/etc/natinst/share/ni-rt.ini"
53+ self .SCP .upload_file (tgt , dest_path )
54+ else :
55+ #Try the FTP, if this fails to connect use SCP
56+ try :
57+ self .FTP .upload_file (tgt , dest_path )
58+ except :
59+ #if error from FTP, use SCP via SSH
60+ self .__9603 = True
61+ #fix the path to ni-rt.ini if ni-rt linux is target
62+ if ("ni-rt.ini" in dest_path ):
63+ dest_path = "/etc/natinst/share/ni-rt.ini"
64+ self .SCP .upload_file (tgt , dest_path )
5165
5266 def apply_config_file (self , cfg_file_path , restart : bool = True ):
5367 """
@@ -428,6 +442,10 @@ def __restart_unit(self):
428442 """
429443 Use nisyscfg library to restart the target unit
430444 """
445+ #need to close SCP helper before restarting so socket isnt force closed
446+ if (self .__9603 ):
447+ #print("Closing SCP connection")
448+ self .SCP .close ()
431449 #open a nisyscfg session to the BS1200 to restart it
432450 with nisyscfg .Session (self .ip_address , self .user , self .pwd ) as s :
433451 #updates IP address for the ConfigTools instance to the new IP address once restart complete
@@ -442,6 +460,11 @@ def __restart_unit(self):
442460 self .FTP .tgt_address = self .ip_address
443461 sys .stdout .flush ()
444462 print ("\r \n " + f"BS1200 at { self .ip_address } is back online" )
463+ sys .stdout .flush ()
464+ print ("\n " )
465+ if (self .__9603 ):
466+ #print("Reopening SCP connection")
467+ self .SCP .open ()
445468
446469 def __animate (self , loadingtext : str ):
447470 """Animation loop for the restart wait"""
0 commit comments