Don't remove invocation from the result in the log callback

Fixes #2064.
Add directory detection to _remote_md5 and use this in copy

If it is a directory, change the destination path by appending the
basename of the source file, like is done if the destination ends with a
/, and try to get the MD5 of the new path.