Improved remote file handling with attachments. Fixes #1910.
Tidy up to use General functions, add some documentation