Skip to content

Retrieving content

Module
Basic Connectivity and Remote Access
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (two lab containers), GNU Bash 5.2.21
On this page

You need a text file from a server, but your terminal shows either a page full of markup or a progress report. Before saving anything, you need to distinguish the server’s content from information about the transfer.

By the end, you can fetch a page, inspect its response headers, save its body under a chosen local name, and read that saved file. You can also recognize an HTTP failure without mistaking it for a failed network path.

Finish Inspecting local connectivity. Use ~/lab from the B04 setup. Reserve the absent directory ~/lab/b14-fetch for this exercise. If you already used it, finish the reset before repeating the steps.

The recording uses the lab server, labserver, on port 80. This is a private Docker bridge between two containers, not a home network or an internet fetch. The hostname works inside that prepared lab. On your own VM, use a web server you control instead; the name labserver will not exist there.

Your addresses, HTTP Date headers, timestamps, and transfer speeds will differ. The capture preserves them as observed. They describe the container network, not your physical computer’s internet speed.

Prepare an empty local directory:

Terminal window
mkdir ~/lab/b14-fetch
cd ~/lab/b14-fetch

Request the lab page:

Terminal window
curl -sS http://labserver/

A URL identifies the resource to request. Here, http selects the protocol, labserver names the host, and / is the path. HTTP uses port 80 by default for this URL. The server returns its index page.

curl transfers data. By default, it writes the response body to standard output, which your terminal displays. The lowercase -s suppresses the progress meter; uppercase -S keeps error messages visible when silent mode is enabled. These options make the body easier to read without hiding a failed request.

The body is the requested content. For this page it is HTML source: text containing tags such as h1 and p. Curl does not render a graphical web page. Seeing markup is expected, rather than evidence that the download is corrupt.

Terminal window
curl -sS -I http://labserver/hello.txt

The uppercase -I requests headers using HTTP’s HEAD method. Headers describe the response; they are separate from the body. This request does not print the text file’s contents.

Predict: will this command print the greeting from the text file after its header lines?

Run it, then compare with your guess
A page body and separate HTTP headers
learner@rootvolt:~/lab/b14-fetch$ curl -sS http://labserver/<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>RootVolt lab server</title></head>
<body>
<h1>RootVolt lab server</h1>
<p>This page is served by the lab server on port 80.</p>
</body>
</html>learner@rootvolt:~/lab/b14-fetch$ curl -sS -I http://labserver/hello.txtHTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.12.3
Date: Sun, 15 Nov 2026 16:07:56 GMT
Content-type: text/plain
Content-Length: 73
Last-Modified: Sun, 15 Nov 2026 00:00:00 GMTlearner@rootvolt:~/lab/b14-fetch$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. The first request prints HTML body text; the second requests only headers for the text resource.
Steps (6)
  1. Type curl -sS http://labserver/
  2. Press Enter
  3. Output: <!doctype html> <html lang="en"> <head><meta charset="utf-8"><title>RootVolt lab server</title></head> <body> <h1>RootVolt lab server</h1> <p>This page is served by the lab server on port 80.</p> </body> </html>
  4. Type curl -sS -I http://labserver/hello.txt
  5. Press Enter
  6. Output: HTTP/1.0 200 OK Server: SimpleHTTP/0.6 Python/3.12.3 Date: Sun, 15 Nov 2026 16:07:56 GMT Content-type: text/plain Content-Length: 73 Last-Modified: Sun, 15 Nov 2026 00:00:00 GMT

No. The headers-only response ends after its metadata. The earlier HTML body belongs to a different request, for the root page.

On a phone, long header lines can wrap. Read the key fields individually:

Response field Captured meaning
HTTP/1.0 200 OK The server reports success for this request
Content-type: text/plain The resource is plain text
Content-Length: 73 The reported body length is 73 bytes
Date The server’s response time; it varies
Last-Modified The resource’s modification timestamp, separate from response time

The first line is the HTTP status line. 200 is a protocol result, not a shell exit status. The shell separately reports whether curl completed successfully. The lab uses a small Python HTTP server; your other servers can report different versions, headers, and capitalization.

Terminal window
curl -sS -o curl.txt http://labserver/hello.txt
cat curl.txt

Lowercase -o takes a local output pathname. It writes the body to curl.txt in your current directory instead of printing it. This command does not include the header lines in the file.

The successful save is quiet because you suppressed the progress meter and redirected the body’s destination with curl’s own option. Silence alone is not the content check. cat reads back the actual saved bytes, letting you confirm that the file contains the greeting.

The remote path is /hello.txt; the local path is ~/lab/b14-fetch/curl.txt. These names need not match. The URL identifies what to retrieve, and the option identifies where to store it locally.

Terminal window
wget -O wget.txt http://labserver/hello.txt
cat wget.txt

For wget, uppercase -O chooses the destination file. The letter’s case matters: curl’s lowercase -o and wget’s uppercase -O are different programs’ options. Wget normally saves a resource to a file and prints a transfer report. Here, choosing a separate name makes the two results easy to inspect.

Save and read a body with two clients
learner@rootvolt:~/lab/b14-fetch$ curl -sS -o curl.txt http://labserver/hello.txtlearner@rootvolt:~/lab/b14-fetch$ cat curl.txtHello from the RootVolt lab server.
This text file is served on port 80.learner@rootvolt:~/lab/b14-fetch$ wget -O wget.txt http://labserver/hello.txt--2026-11-15 16:07:58--  http://labserver/hello.txt
Resolving labserver (labserver)... 172.19.0.2
Connecting to labserver (labserver)|172.19.0.2|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 73 [text/plain]
Saving to: ‘wget.txt’

wget.txt            100%[===================>]      73  --.-KB/s    in 0s      

2026-11-15 16:07:58 (25.8 MB/s) - ‘wget.txt’ saved [73/73]learner@rootvolt:~/lab/b14-fetch$ cat wget.txtHello from the RootVolt lab server.
This text file is served on port 80.learner@rootvolt:~/lab/b14-fetch$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. curl and wget each save the 73-byte text body under a chosen local name; cat verifies both destinations.
Steps (11)
  1. Type curl -sS -o curl.txt http://labserver/hello.txt
  2. Press Enter
  3. Type cat curl.txt
  4. Press Enter
  5. Output: Hello from the RootVolt lab server. This text file is served on port 80.
  6. Type wget -O wget.txt http://labserver/hello.txt
  7. Press Enter
  8. Output: --2026-11-15 16:07:58-- http://labserver/hello.txt Resolving labserver (labserver)... 172.19.0.2 Connecting to labserver (labserver)|172.19.0.2|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 73 [text/plain] Saving to: ‘wget.txt’ wget.txt 100%[===================>] 73 --.-KB/s in 0s 2026-11-15 16:07:58 (25.8 MB/s) - ‘wget.txt’ saved [73/73]
  9. Type cat wget.txt
  10. Press Enter
  11. Output: Hello from the RootVolt lab server. This text file is served on port 80.

Wget’s report includes the resolved address, port 80, HTTP status 200 OK, and saved size [73/73] in this capture. The content appears when cat reads the file. The transfer report itself is not part of wget.txt.

Both destination options can replace existing files. Use this fresh exercise directory, and do not choose an existing document as the destination. Neither tool needs administrative privileges to write here.

Request a deliberately absent resource:

Terminal window
curl -sS --fail http://labserver/missing.txt

The reset replay below includes the recorded error: curl: (22) The requested URL returned error: 404. The --fail option makes this HTTP failure produce a nonzero curl status, 22 here, and suppresses the error response body.

A 404 means an HTTP server answered but did not find that resource. It is different from failing to resolve the hostname or open the connection. Without --fail, curl can successfully transfer an HTTP error page and still report transfer success. Do not treat a saved file’s mere existence as evidence that it is the intended resource.

Saving the headers when you wanted the body. -I asks for headers only. Remove that option for an ordinary body request.

Expecting curl to display a rendered web page. It prints the body bytes. HTML source is the body for the lab’s root page.

Calling every failure “offline.” The recorded 404 is a response from a reachable HTTP server. Inspect the URL path before changing network settings.

Goal: Explain which file would change if you chose note.txt as the local output name while keeping the URL /hello.txt unchanged. Would the server file be renamed?

Solution

The downloaded body would be written to local note.txt. The server still serves /hello.txt; the local destination option does not rename or modify that remote resource. Check the saved content before using it.

Remove only the two known local downloads, leave the directory, and remove it while empty:

Terminal window
rm curl.txt wget.txt
cd ~/lab
rmdir ~/lab/b14-fetch
test ! -e ~/lab/b14-fetch && printf 'Reset complete\n'
Recognize HTTP failure and remove downloads
learner@rootvolt:~/lab/b14-fetch$ curl -sS --fail http://labserver/missing.txtcurl: (22) The requested URL returned error: 404learner@rootvolt:~/lab/b14-fetch$ rm curl.txt wget.txtlearner@rootvolt:~/lab/b14-fetch$ cd ~/lablearner@rootvolt:~/lab$ rmdir ~/lab/b14-fetchlearner@rootvolt:~/lab$ test ! -e ~/lab/b14-fetch && printf 'Reset complete\n'Reset completelearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. An absent URL produces a real 404 failure; the remaining commands remove both downloads and confirm the exercise directory is absent.
Steps (12)
  1. Type curl -sS --fail http://labserver/missing.txt
  2. Press Enter
  3. Output: curl: (22) The requested URL returned error: 404
  4. Type rm curl.txt wget.txt
  5. Press Enter
  6. Type cd ~/lab
  7. Press Enter
  8. Type rmdir ~/lab/b14-fetch
  9. Press Enter
  10. Type test ! -e ~/lab/b14-fetch && printf 'Reset complete\n'
  11. Press Enter
  12. Output: Reset complete

The server’s fixed files were only read. There are no remote changes to undo. Successful rmdir and the final absence test establish the local reset.

  • A body contains resource data; headers describe the response.
  • Curl normally prints the body; -I requests only headers.
  • Choose local destinations with curl -o or wget -O, then read the saved content.
  • An HTTP error and a shell exit status are separate results.

Next, First SSH connection verifies the server identity before opening a remote shell.