Skip to content

download_file() improvements #3331

@jay7x

Description

@jay7x

Use Case

The existing approach with storing a file downloaded to the $destination directory under the basename($source) file name is quite limiting.. Downloading bunch of files from a host or downloading files with the same name but different path from a host makes it especially painful.

Describe the Solution You Would Like

  1. It'd be nice if download_file() accepts an Array as a source. This way we can download bunch of files with one call. That opens another question how to download a bunch of files within one transport connection, but it's another question.
  2. Make $destination a dynamic template, which can accept the source file name and a host name as a parameters. For example:
$res = download_file(['/tmp/1/example.txt', '/tmp/2/example.txt'], 'examples/<%= md5sum($hostname)[1,8] %>/<%= $source_path.regsubst('[/]', '_') %>/<%= shellquote($source_filename) %>.txt', _dynamic_destination => true)

Side notes

  1. That allows to solve download_file shouldn't be destructive #3198 also. No real reason to wipe the target directory I guess.
  2. Maybe it's better to implement another function instead of extending the download_file() (download_files())?. Though, there is no breaking change as long as template processing is requested explicitly in the $options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew features and improvements.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions