Copy a file or directory from a remote location.

    A thin wrapper around the scp (1) system command.

    If the destination already exists, this will attempt to overwrite
    it.

    Arguments:

        host (str): name of the host
        src (str): path to the source file or directory.
        dst (str): path to the destination file or directory.
        user (str, optional): Alternative username for remote access.
          If not provided, the default scp behaviour is used.
        path (str, optional): Directory containing scp command. If not
          provided, attempt to locate scp using which().

    Raises:

        CommandNotFoundError: If scp binary not found.
        IOError: if transfer fails.

def scp(host, src, dst, user=None, path=None):
    """
    Copy a file or directory from a remote location.

    A thin wrapper around the scp (1) system command.

    If the destination already exists, this will attempt to overwrite
    it.

    Arguments:

        host (str): name of the host
        src (str): path to the source file or directory.
        dst (str): path to the destination file or directory.
        user (str, optional): Alternative username for remote access.
          If not provided, the default scp behaviour is used.
        path (str, optional): Directory containing scp command. If not
          provided, attempt to locate scp using which().

    Raises:

        CommandNotFoundError: If scp binary not found.
        IOError: if transfer fails.
    """
    # Create the first argument.
    if user is None:
        arg = "{host}:{path}".format(host=host, path=src)
    else:
        arg = "{user}@{host}:{path}".format(user=user, host=host, path=src)

    # Get path to scp binary.
    scp_bin = which("scp", path=(path,))
    if scp_bin is None:
        raise CommandNotFoundError("Could not find scp in '{0}'".format(path))

    # Run system "scp" command.
    ret,out,err = run([scp_bin,
                       "-o", "StrictHostKeyChecking=no",
                       "-o", "UserKnownHostsFile=/dev/null",
                       arg, dst])

    # Check return code for error.
    if ret:
        raise ScpError(out, err)