def copyFileLinuxToLocalLinux(self, linuxApiServerPathAndFileName, localPath, renameDestinationFile=None, includeTimestamp=False, linuxApiServerPathExtension=None): """ Description Copy files from Linux API Server to local Linux filesystem. The filename to be copied will remain the same filename unless you set renameDestinationFile to something you otherwise preferred. You could also include a timestamp for the destination file. Parameters linuxApiServerPathAndFileName: (str): The full path and filename to retrieve. linuxApiServerPathExtension: (str): In a situation such as packet capture for Linux API server only, the captured file is saved at 'captures//file. Value example: 'captures/packetCaptureFolder/port2_HW.cap' localPath: (str): The Linux destination path to put the file to. renameDestinationFile: (str): You could rename the destination file. includeTimestamp: (bool): If False, each time you copy the same file will be overwritten. Syntax post: /api/v1/sessions/1/ixnetwork/operations/copyfile data: {'arg1': '/root/.local/share/Ixia/sdmStreamManager/common/bgpExportedConfigFile', 'arg2': '/api/v1/sessions/1/ixnetwork/files/'+fileName'} """ import datetime self.ixnObj.logInfo('\ncopyFileLinuxToLocalLinux: From: %s to %s\n' % (linuxApiServerPathAndFileName, localPath)) fileName = linuxApiServerPathAndFileName.split('/')[-1] fileName = fileName.replace(' ', '_') destinationPath = self.ixnObj.sessionUrl.split(self.ixnObj.httpHeader)[1] destinationPath = destinationPath + '/files/' + fileName currentTimestamp = datetime.datetime.now().strftime('%H%M%S') # Step 1 of 3: url = self.ixnObj.sessionUrl+'/operations/copyfile' response = self.ixnObj.post(url, data={"arg1": linuxApiServerPathAndFileName, "arg2": destinationPath}) # Step 2 of 3: if linuxApiServerPathExtension: # Situations like packet capturing puts the captured file in 'captures//' fileName = linuxApiServerPathExtension response = self.ixnObj.get(self.ixnObj.sessionUrl+'/files?filename=%s' % (fileName), stream=True, ignoreError=True) if response.status_code == 200: if renameDestinationFile is not None: fileName = renameDestinationFile if linuxApiServerPathExtension: # This extension means that it has an extended path: captures//fileToGet fileName = linuxApiServerPathExtension.split('/')[-1] contents = response.raw.read() if includeTimestamp: if linuxApiServerPathAndFileNameAsIs: fileName = fileName.split('/')[-1] tempFileName = fileName.split('.') if len(tempFileName) > 1: extension = fileName.split('.')[-1] fileName = tempFileName[0]+'_' + currentTimestamp + '.' + extension else: fileName = tempFileName[0]+'_' + currentTimestamp localPath = localPath+'/'+fileName else: localPath = localPath+'/'+fileName # Step 3 of 3: self.ixnObj.logInfo('\ncopyFileLinuxToLocalLinux: %s' % localPath) with open(localPath, 'wb') as downloadedFileContents: downloadedFileContents.write(contents) self.ixnObj.logInfo('\nA copy of your saved file/report is in:\n\t%s' % (linuxApiServerPathAndFileName)) else: self.ixnObj.logInfo('\ncopyFileLinuxToLocalLinux Error: Failed to download file from Linux API Server.')