def Run(self, args): """Downloads files/directories with the given path.""" try: directory = aff4.FACTORY.Open(args.path, "AFF4Volume", token=data_store.default_token) except aff4.InstantiationError: directory = None if directory and not isinstance(directory, aff4.VFSDirectory): # If directory is not a VFSDirectory, check that it's in its' parent # children list. This way we check that the path actually exists. directory_parent = aff4.FACTORY.Open( directory.urn.Dirname(), token=data_store.default_token) if directory.urn not in directory_parent.ListChildren(): raise RuntimeError("Specified path %s doesn't exist!" % directory.urn) if directory: export_utils.RecursiveDownload(directory, args.output, overwrite=args.overwrite, max_depth=args.depth, max_threads=args.threads) else: export_utils.CopyAFF4ToLocal(args.path, args.output, overwrite=args.overwrite, token=data_store.default_token)
def testRecursiveDownload(self): """Check we can export a file without errors.""" with utils.TempDirectory() as tmpdir: export_utils.RecursiveDownload( aff4.FACTORY.Open(self.out, token=self.token), tmpdir, overwrite=True) expected_outdir = os.path.join(tmpdir, self.out.Path()[1:]) self.assertTrue("testfile1" in os.listdir(expected_outdir)) full_outdir = os.path.join(expected_outdir, "testdir1", "testdir2") self.assertTrue("testfile4" in os.listdir(full_outdir))
def Run(self, args): """Downloads files/directories with the given path.""" try: directory = aff4.FACTORY.Open(args.path, "VFSDirectory", token=data_store.default_token) except aff4.InstantiationError: directory = None if directory: export_utils.RecursiveDownload(directory, args.output, overwrite=args.overwrite, max_depth=args.depth, max_threads=args.threads) else: export_utils.CopyAFF4ToLocal(args.path, args.output, overwrite=args.overwrite, token=data_store.default_token)
def Run(self, args): """Downloads files/directories with the given path.""" # If we're exporting a path inside a client, check to see if we have access # to that client and get the appropriate token. This means we can avoid # having to specify --reason. client_id = client.GetClientURNFromPath(args.path) if client_id is not None: token = security.Approval.GetApprovalForObject( client_id, token=data_store.default_token, username=data_store.default_token.username) data_store.default_token = token try: directory = aff4.FACTORY.Open(args.path, "AFF4Volume", token=data_store.default_token) except aff4.InstantiationError: directory = None if directory and not isinstance(directory, aff4.VFSDirectory): # If directory is not a VFSDirectory, check that it's in its' parent # children list. This way we check that the path actually exists. directory_parent = aff4.FACTORY.Open( directory.urn.Dirname(), token=data_store.default_token) if directory.urn not in directory_parent.ListChildren(): raise RuntimeError("Specified path %s doesn't exist!" % directory.urn) if directory: export_utils.RecursiveDownload(directory, args.output, overwrite=args.overwrite, max_depth=args.depth, max_threads=args.threads) else: export_utils.CopyAFF4ToLocal(args.path, args.output, overwrite=args.overwrite, token=data_store.default_token)
def Run(self, args): """Downloads files/directories with the given path.""" base_url = config_lib.CONFIG.Get("AdminUI.url", context=["AdminUI Context"]) source_path = rdfvalue.RDFURN(args.path) components = source_path.Split(2) try: directory = aff4.FACTORY.Open(args.path, aff4.AFF4Volume, token=data_store.default_token) except aff4.InstantiationError: directory = None if directory and not isinstance(directory, standard.VFSDirectory): # If directory is not a VFSDirectory, check that it's in its' parent # children list. This way we check that the path actually exists. directory_parent = aff4.FACTORY.Open( directory.urn.Dirname(), token=data_store.default_token) if directory.urn not in directory_parent.ListChildren(): raise RuntimeError("Specified path %s doesn't exist!" % directory.urn) if directory: url = "%s/#/clients/%s/vfs/%s" % (base_url, components[0], components[1]) print "=============================================================" print( "WARNING: Command line export tool is DEPRECATED and will be " "removed soon.") print print( "Please use the 'Download files collected in folder' button " "instead. The archive will be generated on the fly:") print url print print "=============================================================" print if not args.no_legacy_warning_pause: raw_input("Press Enter if you still want to continue...") export_utils.RecursiveDownload(directory, args.output, overwrite=args.overwrite, max_depth=args.depth, max_threads=args.threads) else: url = "%s/#/clients/%s/vfs/%s?tab=download" % ( base_url, components[0], components[1]) print "=============================================================" print( "WARNING: Command line export tool is DEPRECATED and will be " "removed soon.") print print( "Please use the 'Download' tab in the 'Browse Virtual Filesystem' " "instead:") print url print print "=============================================================" print if not args.no_legacy_warning_pause: raw_input("Press Enter if you still want to continue...") export_utils.CopyAFF4ToLocal(args.path, args.output, overwrite=args.overwrite, token=data_store.default_token)