#!/bin/bash # # Send files with netcat, using an standard http header # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # (C) 2007 Jose L. Hidalgo ValiƱo (pplux@pplux.com) # export LANG=C # Port to use... PORT=6969 # Check file [ -f $1 ] || { echo "Error can not open \"$1\""; exit 1; } TYPE=unknown which file 2>&1 1>/dev/null && TYPE=`file -bi $1` LENGTH=`du -b $1 | awk '{print $1}'` NAME=${1##*/} # Alternatives to download the file: if [ $OSTYPE = "cygwin" ]; then for ip in $(ipconfig | awk '/IP.*[0-9]/{match($NF,/[0-9.:]*/);print substr($NF,RSTART,RLENGTH)}');do echo "http://$ip:$PORT/$NAME" done else for ip in $(ifconfig | awk '/inet addr/{sub(/addr:/,"",$2);print $2}');do echo "http://$ip:$PORT/$NAME" done fi echo "-- Waiting for connection....." # Execute netcat with http header ( echo -e "HTTP/1.1 200 OK\r" echo -e "Connection: close\r" echo -e "Content-Length: $LENGTH\r" echo -e "Content-Type: $TYPE\r" echo -e "\r" cat $1 echo -e "\r" ) | nc -l -p $PORT