I just want to share with you the complete solution that you can use to expose/make available a file via a network between remote computers with Netcat.
I use this perfect and simple solution to share a file between Docker Containers in a portable way without defining Docker Volume
or installing ssh
in the Docker container.
A simple bash function that exposes the file on the source machine:
# ------------------------------------------------------------------------------
# make the file available for another machine via the network
#
# this runs in the background to avoid blocking the main script execution
# ------------------------------------------------------------------------------
function exposeFile() {
local file port
file="$1"
port=1384
echo "exposing the file for another machine with..."
echo " file: $file"
echo " port: $port"
while :
do
{ echo -ne "HTTP/1.0 200 OK
"; cat "$file" ; } | nc -l "$port"
done
}
The endless loop is necessary if you want to download the file more than one time because after the download Netcat
exists.
Call the bash method from your main script to expose the file when you need it:
#!/bin/bash
...
exposeFile "path/to/the/file.zip" &
Then you can use the a simple wget
to download the file on the source machine:
function fileDownload {
echo "downloading the file..."
local fileHome file
fileHome="/download/directory/"
file="myfile.zip"
local remoteHost remotePort
remoteHost="remote-host-or-ip"
remotePort=1384
mkdir -p "$fileHome"
wget -O "$fileHome/$file" "$remoteHost":"$remotePort"
}
I hope that this will help you to save some time ;)