def downloadResource(connection, downloadFolder, localPath, zipName="", timeout=80): ''' This method is used to download an entire folder as an archive or any type of file without changing it's format Args: - connection is the connection object that manages the HTTP data transfers between the client and the REST API - downloadFolder is the folder were the archive/file will be saved - localPath is the local path on the machine that holds the IxLoad instance - zipName is the name that archive will take, this parameter is mandatory only for folders, if you want to download a file this parameter is not used. ''' downloadResourceUrl = connection.url + "/downloadResource" downloadFolder = downloadFolder.replace("\\\\", "\\") localPath = localPath.replace("\\", "/") parameters = { "localPath": localPath, "zipName": zipName } downloadResourceReply = connection.httpRequest('GET', downloadResourceUrl, params= parameters, downloadStream=True, timeout =timeout) if not downloadResourceReply.ok: raise Exception("Error on executing GET request on url %s: %s" % (downloadResourceUrl, downloadResourceReply.text)) if not zipName: zipName = localPath.split("/")[-1] elif zipName.split(".")[-1] != "zip": zipName = zipName + ".zip" downloadFile = '/'.join([downloadFolder, zipName]) try: with open(downloadFile, 'wb') as fileHandle: for chunk in downloadResourceReply.iter_content(chunk_size=1024): fileHandle.write(chunk) except IOError: log("Could not open or create file, please check path and/or permissions") return 2