\(\renewcommand\AA{\unicode{x212B}}\)

DownloadFile v1

Summary

Downloads a file from a url to the file system

See Also

Load, CatalogDownloadDataFiles

Properties

Name

Direction

Type

Default

Description

Address

InOut

string

Mandatory

The address of the network resource to download.

Filename

Input

string

Mandatory

The filename to save the download to.

Description

This is a simple algorithm that will download the contents of a url address to a file. It can support http:// and https:// based urls, and if the method is not supplied then http:// will be assumed. For example: If the address is www.mantidproject.org, then this will be adjusted to http://www.mantidproject.org.

Usage

Example - http

#import the os path libraries for directory functions
import os

#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "DownloadedFile.txt")

DownloadFile("http://www.mantidproject.org", savefile)

print("File Exists: {}".format(os.path.exists(savefile)))

Output:

File Exists: True

Example - https

#import the os path libraries for directory functions
import os

#Create an absolute path by joining the proposed filename to a directory
#os.path.expanduser("~") used in this case returns the home directory of the current user
savefile = os.path.join(os.path.expanduser("~"), "DownloadedFile.txt")

DownloadFile("https://raw.githubusercontent.com/mantidproject/mantid/master/README.md", savefile)

print("File Exists:".format(os.path.exists(savefile)))

Output:

File Exists: True

Categories: AlgorithmIndex | DataHandling

Source

C++ header: DownloadFile.h

C++ source: DownloadFile.cpp