(self, src, dest, configuration_name=DEFAULT_CONFIGURATION_NAME,
              expand_variables=False)
Will fetch a single file from the remote Windows host and create a
        local copy. Like copy(), this can be slow when it comes to fetching
        large files due to the limitation of WinRM.

        This method will first store the file in a temporary location before
        creating or replacing the file at dest if the checksum is correct.

        :param src: The path to the file on the remote host to fetch
        :param dest: The path on the localhost host to store the file as
        :param configuration_name: The PowerShell configuration endpoint to
            use when fetching the file.
        :param expand_variables: Expand variables in path. Disabled by default
            Enable for cmd like expansion (for example %TMP% in path)
Will fetch a single file from the remote Windows host and create a
        local copy. Like copy(), this can be slow when it comes to fetching
        large files due to the limitation of WinRM.
Will fetch a single file from the remote Windows host and create a local copy . Like copy () this can be slow when it comes to fetching large files due to the limitation of WinRM .
def fetch(self, src, dest, configuration_name=DEFAULT_CONFIGURATION_NAME,
              expand_variables=False):
        """
        Will fetch a single file from the remote Windows host and create a
        local copy. Like copy(), this can be slow when it comes to fetching
        large files due to the limitation of WinRM.

        This method will first store the file in a temporary location before
        creating or replacing the file at dest if the checksum is correct.

        :param src: The path to the file on the remote host to fetch
        :param dest: The path on the localhost host to store the file as
        :param configuration_name: The PowerShell configuration endpoint to
            use when fetching the file.
        :param expand_variables: Expand variables in path. Disabled by default
            Enable for cmd like expansion (for example %TMP% in path)
        """
        if expand_variables:
            dest = os.path.expanduser(os.path.expandvars(dest))
        log.info("Fetching '%s' to '%s'" % (src, dest))

        with RunspacePool(self.wsman, configuration_name=configuration_name) as pool:
            script = get_pwsh_script('fetch.ps1')
            powershell = PowerShell(pool)
            powershell.add_script(script) \
                .add_argument(src) \
                .add_argument(expand_variables)

            log.debug("Starting remote process to output file data")
            powershell.invoke()
            _handle_powershell_error(powershell, "Failed to fetch file %s" % src)
            log.debug("Finished remote process to output file data")

            expected_hash = powershell.output[-1]

            temp_file, path = tempfile.mkstemp()
            try:
                file_bytes = base64.b64decode(powershell.output[0])
                os.write(temp_file, file_bytes)

                sha1 = hashlib.sha1()
                sha1.update(file_bytes)
                actual_hash = sha1.hexdigest()

                log.debug("Remote Hash: %s, Local Hash: %s"
                          % (expected_hash, actual_hash))
                if actual_hash != expected_hash:
                    raise WinRMError("Failed to fetch file %s, hash mismatch\n"
                                     "Source: %s\nFetched: %s"
                                     % (src, expected_hash, actual_hash))
                shutil.copy(path, dest)
            finally:
                os.close(temp_file)
                os.remove(path)
def fetch ( self , src , dest , configuration_name = DEFAULT_CONFIGURATION_NAME , expand_variables = False ) : if expand_variables : dest = os . path . expanduser ( os . path . expandvars ( dest ) ) log . info ( "Fetching '%s' to '%s'" % ( src , dest ) ) with RunspacePool ( self . wsman , configuration_name = configuration_name ) as pool : script = get_pwsh_script ( 'fetch.ps1' ) powershell = PowerShell ( pool ) powershell . add_script ( script ) . add_argument ( src ) . add_argument ( expand_variables ) log . debug ( "Starting remote process to output file data" ) powershell . invoke ( ) _handle_powershell_error ( powershell , "Failed to fetch file %s" % src ) log . debug ( "Finished remote process to output file data" ) expected_hash = powershell . output [ - 1 ] temp_file , path = tempfile . mkstemp ( ) try : file_bytes = base64 . b64decode ( powershell . output [ 0 ] ) os . write ( temp_file , file_bytes ) sha1 = hashlib . sha1 ( ) sha1 . update ( file_bytes ) actual_hash = sha1 . hexdigest ( ) log . debug ( "Remote Hash: %s, Local Hash: %s" % ( expected_hash , actual_hash ) ) if actual_hash != expected_hash : raise WinRMError ( "Failed to fetch file %s, hash mismatch\n" "Source: %s\nFetched: %s" % ( src , expected_hash , actual_hash ) ) shutil . copy ( path , dest ) finally : os . close ( temp_file ) os . remove ( path )