Created
April 10, 2024 17:17
-
-
Save agustik/5db8ce0807a0764bafd6882c09db0084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
port=$(shuf -i 9000-60000 -n 1) | |
file=$1 | |
if [[ -z "$1" ]]; then | |
echo "Missing file, use $0 <file>" | |
exit 1 | |
fi | |
md5=$(md5sum $file | awk '{ print $1 }') | |
name=$(basename "$file") | |
primaryip=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+') | |
echo "Serving file on $port | |
# To fetch the file use: | |
# curl http://$HOSTNAME:$port -o $name | |
# Or using ip | |
# curl http://$primaryip:$port -o $name | |
# | |
# Check the content, md5sum $name it should be: | |
# $md5 | |
# Hint, you might need to turn of your firewall | |
# sudo systecmtl stop iptables | |
# " | |
cat <(echo "HTTP/1.1 200 OK | |
Content-Type: Content-type: application/octet-stream | |
E-Tag: $md5 | |
Content-Disposition: attachment; filename=\"$name\" | |
Content-Length: $( du -b $file ) | |
Server: Netcat | |
" ) $file | nc -l $port > /dev/null | |
echo "Transfer complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple http server to transfer files between linux servers.