11from nxc .connection import connection
22from nxc .logger import NXCAdapter
3- from pyNfsClient import Portmap , Mount , NFSv3 , NFS_PROGRAM , NFS_V3 , ACCESS3_READ , ACCESS3_MODIFY , ACCESS3_EXECUTE
3+ from pyNfsClient import Portmap , Mount , NFSv3 , NFS_PROGRAM , NFS_V3 , ACCESS3_READ , ACCESS3_MODIFY , ACCESS3_EXECUTE , NFSSTAT3
44import re
55import uuid
66import math
@@ -323,19 +323,17 @@ def put_file(self):
323323
324324 # Create file
325325 self .logger .display (f"Trying to create { remote_file_path } { file_name } " )
326- self .nfs3 .create (dir_handle , file_name , 1 , auth = self .auth )
327- self .logger .success (f"{ file_name } successfully created." )
326+ res = self .nfs3 .create (dir_handle , file_name , create_mode = 1 , mode = 0o777 , auth = self .auth )
327+ if res ["status" ] != 0 :
328+ raise Exception (NFSSTAT3 [res ["status" ]])
329+ else :
330+ file_handle = res ["resok" ]["obj" ]["handle" ]["data" ]
331+ self .logger .success (f"{ file_name } successfully created" )
328332 except Exception as e :
329- self .logger .fail (f"{ file_name } was not created." )
330- self .logger .debug (f"Error while creating remote file: { e } " )
331- exit (- 1 )
333+ self .logger .fail (f"{ file_name } was not created: { e } " )
334+ return
332335
333336 try :
334- # Mount the NFS share to write the file
335- mnt_info = self .mount .mnt (remote_file_path + "/" + file_name , self .auth )
336- file_handle = mnt_info ["mountinfo" ]["fhandle" ]
337- attrs = self .nfs3 .getattr (file_handle , auth = self .auth )
338- self .auth ["uid" ] = attrs ["attributes" ]["uid" ]
339337 with open (local_file_path , "rb" ) as file :
340338 file_data = file .read ().decode ()
341339
@@ -344,9 +342,7 @@ def put_file(self):
344342 self .nfs3 .write (file_handle , 0 , len (file_data ), file_data , 1 , auth = self .auth )
345343 self .logger .success (f"Data from { local_file_path } successfully written to { remote_file_path } " )
346344 except Exception as e :
347- self .logger .fail (f"{ local_file_path } was not writed." )
348- self .logger .debug (f"Error while creating remote file: { e } " )
349- exit (- 1 )
345+ self .logger .fail (f"Could not write to { local_file_path } : { e } " )
350346
351347 # Unmount the share
352348 self .mount .umnt (self .auth )
0 commit comments