def copyFileWindowsToLocalLinux(self, windowsPathAndFileName, localPath, renameDestinationFile=None, includeTimestamp=False): """ Description Copy files from the IxNetwork API Server c: drive 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 windowsPathAndFileName: (str): The full path and filename to retrieve from Windows client. 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': windowsPathAndFileName, 'arg2': '/api/v1/sessions/1/ixnetwork/files/'+fileName'} """ import datetime self.ixnObj.logInfo('\ncopyFileWindowsToLocalLinux: From: %s to %s\n' % (windowsPathAndFileName, localPath)) fileName = windowsPathAndFileName.split('\\')[-1] fileName = fileName.replace(' ', '_') destinationPath = '{0}/ixnetwork/files/'.format(self.ixnObj.headlessSessionId) + fileName currentTimestamp = datetime.datetime.now().strftime('%H%M%S') # Step 1 of 2: url = self.ixnObj.sessionUrl+'/operations/copyfile' response = self.ixnObj.post(url, data={"arg1": windowsPathAndFileName, "arg2": destinationPath}) # curl http://{apiServerIp:port}/api/v1/sessions/1/ixnetwork/files/AggregateResults.csv -O -H "Content-Type: application/octet-stream" -output /home/hgee/AggregateResults.csv # Step 2 of 2: #requestStatus = self.ixnObj.get(self.ixnObj.sessionUrl+'/files/%s' % (fileName), stream=True, ignoreError=True) url = self.ixnObj.sessionUrl+'/files?filename=%s' % (fileName) requestStatus = self.ixnObj.get(url, stream=True, ignoreError=True) if requestStatus.status_code == 200: if renameDestinationFile is not None: fileName = renameDestinationFile contents = requestStatus.raw.read() if includeTimestamp: 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 with open(localPath, 'wb') as downloadedFileContents: downloadedFileContents.write(contents) self.ixnObj.logInfo('\nA copy of your saved file/report is in:\n\t%s' % (windowsPathAndFileName)) self.ixnObj.logInfo('\ncopyFileWindowsToLocalLinux: %s' % localPath) else: self.ixnObj.logInfo('\ncopyFileWindowsToLocalLinux Error: Failed to download file from IxNetwork API Server.')