OpenMS
Loading...
Searching...
No Matches
Network Class Reference

Convenience wrapper around NetworkGetRequest for one-shot HTTP/HTTPS downloads. More...

#include <OpenMS/SYSTEM/Network.h>

Static Public Member Functions

static void downloadFile (const std::string &url, const std::string &download_folder)
 Download url to download_folder and return when the file is fully written.
 

Detailed Description

Convenience wrapper around NetworkGetRequest for one-shot HTTP/HTTPS downloads.

Single-method utility used by tooling that needs to fetch a remote URL to disk without composing a NetworkGetRequest pipeline by hand. Synchronous (the call blocks until the transfer finishes or fails).

Member Function Documentation

◆ downloadFile()

static void downloadFile ( const std::string &  url,
const std::string &  download_folder 
)
static

Download url to download_folder and return when the file is fully written.

Internally creates a NetworkGetRequest with a 10-minute (600 second) timeout and runs it synchronously. The destination filename is derived from the URL:

  • any "?query" and "#fragment" suffixes are stripped first;
  • the basename of the remaining path component is used (e.g. "https://host/a/b/c.tsv""c.tsv");
  • if the resulting basename is empty, "download" is used as a fallback. If a file with the same name already exists in download_folder, the suffixes ".0", ".1", ".2", ... are tried in order until an unused name is found — existing files are never overwritten.

An empty download_folder is treated as "./" (the current working directory). No trailing-slash normalisation is performed on the directory string.

Success path: writes the response bytes to the destination in binary mode and emits two OPENMS_LOG_INFO lines (download successful + final on-disk path). Failure paths throw:

  • download error (HTTP error or timeout in NetworkGetRequest),
  • opening the destination file fails (e.g. permission denied, missing folder),
  • writing the response bytes fails partway. A partially-written file is not cleaned up on write failure.
Parameters
[in]urlSource URL.
[in]download_folderDestination directory; "" is treated as "./".
Exceptions
OpenMS::Exception::IOExceptionon any of the failure paths described above.