Quick sharing of a single/multiple files in a directory over HTTP protocol will be covered. Let's assume that the file sharing will be done over wlp3s0 Wi-Fi interface and the server's IP address is 192.168.0.24 as shown below:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[johndoe@ArchLinux]% ifconfig
enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 70:8b:cd:12:07:8d txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 117216 bytes 7806522 (7.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 117216 bytes 7806522 (7.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.24 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 2a02:908:1e0:3760:c2d3:1879:cc69:e499 prefixlen 64 scopeid 0x0<global>
inet6 fe80::5047:bc05:eee0:2d3f prefixlen 64 scopeid 0x20<link>
ether 74:df:bf:f0:a9:7c txqueuelen 1000 (Ethernet)
RX packets 935994 bytes 976098812 (930.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 493162 bytes 104280366 (99.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
Python2 SimpleHTTPServer
|
1
2
3
|
[johndoe@ArchLinux]% sudo pip2 install SimpleHTTPServer
[johndoe@ArchLinux]% cd ~/Desktop
[johndoe@ArchLinux]% python2 -m SimpleHTTPServer 8000
|
Open http://192.168.0.24:8000 in your web browser on another computer. You will be able to see the content of directory "~/Desktop".
Python3 HTTPSERVER
|
1
2
3
|
[johndoe@ArchLinux]% sudo pip3 install httpserver
[johndoe@ArchLinux]% cd ~/Desktop
[johndoe@ArchLinux]% python3 -m http.server 8000
|
Open http://192.168.0.24:8000 in your web browser on another computer. You will be able to see the content of directory "~/Desktop".
Python3 QuickServe
|
1
2
|
[johndoe@ArchLinux]% sudo yaourt -S quickserve
[johndoe@ArchLinux]% quickserve -p 8000 ~/Desktop
|
Open http://192.168.0.24:8000 in your web browser on another computer. You will be able to see the content of directory "~/Desktop".
Jupyter Notebook
|
1
2
|
[johndoe@ArchLinux]% cd ~/Desktop
[johndoe@ArchLinux]% jupyter notebook
|
Jupyter Notebook will automatically launch a web browser and open a specific web page.
TWS (Perl)
|
1
2
3
|
[johndoe@ArchLinux]% cd ~/Desktop
[johndoe@ArchLinux]% wget https://raw.githubusercontent.com/waldner/tws/master/tws.pl
[johndoe@ArchLinux]% perl tws.pl FileToShare
|
Only one file at a time is shared.
WWWSHARE (BASH)
Pure BASH solution is depicted here: Simple ad-hoc file sharing.
A slightly modified version for the wlp3s0 interface is given below:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[johndoe@ArchLinux]% cat wwwshare
#!/bin/bash
die() { echo "$*" >&2; exit 1; }
[[ $# != 0 ]] || die "Usage: $0 filename"
[[ -f $1 ]] || die "No such file: $1"
file="$1"
ip_local=$(ip -4 addr show wlp3s0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
port=8081
echo "http://$ip_local:$port/$file"
cat - "$file" << EOF | nc -l -p $port
HTTP/1.1 200 Ok
Content-Type: application/octet-stream
Content-Length: $(stat -c %s "$file")
EOF
|
Install netcat and run the script with a file name as an argument:
|
1
2
|
[johndoe@ArchLinux]% sudo pacman -S gnu-netcat
[johndoe@ArchLinux]% bash wwwshare FileToShare
|
Open web browser at address http://192.168.0.24:8081.
WWWSHARE (GAWK)
Similar version of a BASH solution but with using a GAWK script:
|
1
2
3
4
|
[johndoe@ArchLinux]% sudo pacman -S gnu-netcat
[johndoe@ArchLinux]% wget -vc http://pgas.freeshell.org/shell/wwwshare -O wwwsharegawk
[johndoe@ArchLinux]% chmod +x wwwsharegawk
[johndoe@ArchLinux]% ./wwwsharegawk FileToShare
|
Instead of the external IP address, use the inernal one for interface wlp3s0.
So open http://192.168.0.24:8006/FileToShare instead of http://175.102.234.162:8006/FileToShare for example.