Quick and Easy File Transfer with netrw
Fast Transport
Even without elaborate infrastructure, you can still push your data across the network with netrw.
If you're looking for a quick and easy tool for transferring files, netrw [1] offers an elegant solution. According to the project website, the purpose of netrw is to "simplify and speed up file transfers to hosts without an FTP server." Netrw is also useful for scenarios where the user transferring the file does not have an account on the target machine.
The netrw project consists of two programs, netread
and netwrite
. As the names imply, netwrite
writes the file from the sending machine and netread
reads it on the target. The advantage of this ad hoc solution, compared with solutions in which the daemon listens constantly, is the brief existence of the open channel. This design reduces the likelihood of an attacker accidentally stumbling across the open port.
Netrw gives you the ability to transfer any kind of electronic data. Of course, it's always better to use netrw on a protected network, and you are advised not to use it in an insecure setting. If you do, however, you'll want to protect your privacy by encrypting the payload.
Basic Functions
In the simplest case, start by initializing the reception of data with netread
. You only specify the port number and redirect stdout to a file (Listing 1, line 1). The transfer itself is launched in the same style (line 2).
Listing 1
Configuring Data Reception
Figure 1 shows the transfer sequence. The two programs have common options; the most important ones are described in Table 1.
Table 1
Options for netread and netwrite
Parameter | Explanation |
---|---|
udp |
Uses UDP instead of TCP |
-f <Host> |
Establishes a connection on the read side |
-C <Algorithm> |
Uses specified algorithm (sha1, md5, rmd160, none) |
-o <File> |
Specifies the file |
-h <Value> |
Outputs the progress of all <Value>s (KB) |
-H <Value> |
Outputs the progress of all <Value>s (MB) |
-b |
Specifies speed in bps (instead of Bps) |
-q |
Suppresses screen output |
-v |
Outputs detailed messages |
-vv |
Outputs very detailed messages |
You can either redirect the payload directly from a file or you can use the -i <file>
option in netwrite
. On the target system, use the output redirection (>
) or the -o <file>
option for saving the data.
Progress
The progress indicator proves especially useful for transferring large volumes of data; it lets you check to see whether bytes are actually still flowing across the network. You can choose between a display in kilobytes (-h
) or megabytes (-H
). The option requires you to define the volume of data that triggers a hash mark being written to screen. This can mean that your screen either fills up or shows very little information (Figure 2).
In a shell script (Listing 2) [2], you could use stat
[3] to determine the size of the file and then define a useful integer value for the progress bar. Note that one line is made up of 50 hash marks. Accordingly, you might not see any output for very small volumes of data.
Listing 2
Determining File Size
The receiving side does not know the file size in advance. You can either ask for this value before the transfer is initiated or use a value of 1000
; experience has shown that -H
produces reasonable output.
Figure 3 shows the flow of the script. For clarity, positional parameters are used in place of input templates. You could extend this script accordingly with the capabilities of Zenity [4] or cdialog [5].
Firewall Mode
Firewall mode lets you set up a connection in the reverse direction. You can pass in either the IP address or a hostname using the -f
option. The following workflow has proved useful in practical terms: Call netwrite
with the -f
option, then start netread
also with -f
. This means that you are using firewall mode on both systems, but the startup sequence is the other way around.
In Figure 4, you can see the steps required for the sender (light background in the terminal) and the receiver (dark background). The computers are addressed by their hostnames (ze5
and ZE6
). After the call to netwrite
, you will see a message that the program is listening on the specified port. The other messages are displayed after calling netread
on the target system.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.