Next: , Previous: , Up: Networking Utilities   [Contents][Index]


36.4.2 URL Manipulation

s = urlread (url)
[s, success] = urlread (url)
[s, success, message] = urlread (url)
[…] = urlread (url, method, param)

Download a remote file specified by its url and return its content in string s.

For example:

s = urlread ("ftp://ftp.octave.org/pub/README");

The variable success is 1 if the download was successful, otherwise it is 0 in which case message contains an error message.

If no output argument is specified and an error occurs, then the error is signaled through Octave’s error handling mechanism.

This function uses libcurl. Curl supports, among others, the HTTP, FTP, and FILE protocols. Username and password may be specified in the URL. For example:

s = urlread ("http://user:password@example.com/file.txt");

GET and POST requests can be specified by method and param. The parameter method is either ‘get’ or ‘post’ and param is a cell array of parameter and value pairs. For example:

s = urlread ("http://www.google.com/search", "get",
            {"query", "octave"});

See also: urlwrite.

urlwrite (url, localfile)
f = urlwrite (url, localfile)
[f, success] = urlwrite (url, localfile)
[f, success, message] = urlwrite (url, localfile)

Download a remote file specified by its url and save it as localfile.

For example:

urlwrite ("ftp://ftp.octave.org/pub/README",
          "README.txt");

The full path of the downloaded file is returned in f.

The variable success is 1 if the download was successful, otherwise it is 0 in which case message contains an error message.

If no output argument is specified and an error occurs, then the error is signaled through Octave’s error handling mechanism.

This function uses libcurl. Curl supports, among others, the HTTP, FTP, and FILE protocols. Username and password may be specified in the URL, for example:

urlwrite ("http://username:password@example.com/file.txt",
          "file.txt");

GET and POST requests can be specified by method and param. The parameter method is either ‘get’ or ‘post’ and param is a cell array of parameter and value pairs. For example:

urlwrite ("http://www.google.com/search", "search.html",
          "get", {"query", "octave"});

See also: urlread.


Next: , Previous: , Up: Networking Utilities   [Contents][Index]