11from ftplib import FTP
22from dataclasses import dataclass
3- from paramiko import SSHClient
3+ from paramiko import SSHClient , AutoAddPolicy
44from scp import SCPClient
55
66class FtpHelper (object ):
@@ -12,7 +12,7 @@ def __init__(self, tgt: str, user: str, password : str):
1212 self .username = user
1313 self .password = password
1414
15- def getFile (self , tgt_path , dest_path ) -> str :
15+ def get_file (self , tgt_path , dest_path ) -> str :
1616 try :
1717 with FTP (self .tgt_address , self .username , self .password ) as f :
1818 with open (dest_path , "wb" ) as file :
@@ -22,7 +22,7 @@ def getFile(self, tgt_path, dest_path) -> str:
2222 except Exception as e :
2323 raise e
2424
25- def uploadFile (self , src_path , tgt_path ):
25+ def upload_file (self , src_path , tgt_path ):
2626 try :
2727 with FTP (self .tgt_address , self .username , self .password ) as f :
2828 with open (src_path , "rb" ) as file :
@@ -32,27 +32,32 @@ def uploadFile(self, src_path, tgt_path):
3232
3333class ScpHelper (object ):
3434 """
35- Class used to wrap SSH and SCP file transfer for sbRIO 9603 controllers. Call using 'with' statements, or call open
35+ Class used to wrap SSH and SCP file transfer for sbRIO 9603 controllers.
36+ Call using 'with' statements, or call open
3637 """
3738 def __init__ (self , tgt : str , user : str , password : str ):
3839 self .tgt_address = tgt
3940 self .username = user
4041 self .password = password
4142
42- def __enter__ (self ):
43+ def __enter__ (self , * args , ** kwargs ):
4344 try :
4445 self .open ()
4546 except Exception as e :
4647 print (e )
48+ return self
4749
48- def __exit__ (self ):
50+ def __exit__ (self , * args , ** kwargs ):
4951 self .close ()
5052
5153 def open (self ):
5254 """Open """
5355 self .ssh = SSHClient ()
5456 self .ssh .load_system_host_keys ()
55- self .ssh .connect (self .tgt_address )
57+ self .ssh .set_missing_host_key_policy (AutoAddPolicy ())
58+ self .ssh .connect (self .tgt_address ,
59+ username = self .username ,
60+ password = self .password )
5661 # SCPCLient takes a paramiko transport as an argument
5762 self .scp = SCPClient (self .ssh .get_transport ())
5863
@@ -61,15 +66,15 @@ def close(self):
6166 self .scp .close ()
6267 self .ssh .close ()
6368
64- def getFile (self , tgt_path , dest_path ) -> str :
69+ def get_file (self , tgt_path , dest_path ) -> str :
6570 try :
6671 with self .scp as s :
6772 s .get (remote_path = tgt_path , local_path = dest_path )
6873 return dest_path
6974 except Exception as e :
7075 print (e )
7176
72- def uploadFile (self , src_path , tgt_path ):
77+ def upload_file (self , src_path , tgt_path ):
7378 try :
7479 with self .scp as s :
7580 s .put (files = src_path , remote_path = tgt_path )
0 commit comments