For some reason this was hard to find clear instructions for. I found a bunch of stack exchange articles but syntax and other things made it harder than it should have been. Once I actually got it working it was nice and simple and a good life skill…
Objective
- Be able to move files from one ubuntu machine to another ubuntu machine
- Both machines are on the same LAN
- Did not want to bother finding, installing apps and software (like messengers, etc), or had problems with a sharing app
- Wanted to learn a quick and dirty skill to be able to do this anywhere I find myself
Overview of Solution
- Open a super basic HTTP web server on the ubuntu machine hosting the files/directories
- Connect to the host machine from the client machine
- Transfer file(s) using
wget
command
Solution – Host machine
- Know and maybe write down the IP address of this host machine by running
ifconfig
(may need to first install `net-tools`) - Navigate to the place where all your files are using
cd
commands - Start a basic web host with python using this syntax where you choose your favourite port number:
sudo python3 -m http.server {port}
- Example:
sudo python3 -m http.server 29
This should open up a running dialogue on your terminal screen that looks like this while it’s waiting for action:
Serving HTTP on 0.0.0.0 port 29 (http://0.0.0.0:29/) ...
Solution – Client machine
- Make sure you have available the IP address of the host from step 1 above
- Punch in the
wget
command with this kind of syntax:wget -r http://{123.123.123.123}:{port}/{filename.txt}
So let’s say your host’s IP address was 192.168.1.12, your port that you opened on the host was 29 and the filename was super_cats.txt (and it was actually located in the place where you ran your python script on the host), your command would look like this:
wget -r http://192.168.1.12:29/super_cats.txt
And if it was successful
--2024-09-17 10:57:30-- http://192.168.1.12:29/super_cats.txt
Connecting to 192.168.1.12:29... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10 [text/plain]
Saving to: ‘192.168.1.12:29/super_cats.txt’
192.168.1.12:29/super_cats.txt 100%[======================================================>] 10 --.-KB/s in 0s
2024-09-17 10:57:30 (510 KB/s) - ‘192.168.1.12:29/super_cats.txt’ saved [10/10]
FINISHED --2024-09-17 10:57:30--
Total wall clock time: 0.5s
Downloaded: 1 files, 10 in 0s (510 KB/s)
NOTE! It seems like this setup automatically creates a directory with the IP address of the host you connected to on the client’s machine and inside that you’ll find your super_cats.txt file (inside a directory called {ip:port} such as 192.168.1.12:29
Wrapping up
Be sure to close your HTTP connection on the host machine!
It’s unwise to leave doors unlocked.
You can do this with a simple control+c
on your keyboard to stop the host from hosting.
Pro Tips
- If you find you can’t seem to connect to host, check to see if by chance you’re trying to connect from a wireless router on a different IP range – happened to me once. I had to disconnect ethernet, connect to wifi, and then the two found each other….
- BEEBEEP is another fantastic solution (better) if you have time and resources. An amazing LAN messenger project.
Conclusion
Now you can flex your terminal pectorals by quickly moving files between two machines and hope it helps