File Transfer Using Ncat
·
Table of Contents
Hi,
today seiichiro0185 and I have found a fast and unusual way to copy files.
Security
By following these steps you will provide a service via network.
This might lead to a vulnerable systems.
Therefore make sure to restrict the access to the service for example by configuring your firewall accordingly.
Warranty
There is no warranty that this setup works for any system which provide the dependencies listed below.
I'm just providing these information because it worked for me.
If you have questions you can leave a message here but I decide whether I'll answer and help or not.
Dependencies:
- ncat (mostly provided by nmap)
Setup #
file recieving system #
-
copy this script on your system which should recieve the files:
#!/bin/bash # directory all files and folders will be copied into basedir="/<any base directory>/" read filename echo "$filename" >&2 if [[ "${filename}" =~ / ]] then [ -d "${basedir}/${filename%%/*}" ] || mkdir -p "${basedir}/${filename%%/*}" fi cat - > "${basedir}/${filename}"
-
run the following command:
ncat -lkvnp 3334 --recv-only -e /path/to/your/recv-file.sh
Now the server is running and listening on port 3334. All files and directories are created with permissions of the running ncat.
file sending system #
-
copy the following script on the system you to send files from:
#!/bin/bash host="$1" port="$2" [[ ${port} =~ ^[0-9][0-9]*$ ]] || { echo "The given port $port (2. argument) is not valid." >&2 && exit 1 ; } shift 2 IFS="," for f in $@ do { echo "${f}" && cat "${f}" ; } | ncat -i1 $host $port done
-
use the script like this:
bash send-file.sh <host> <port> <file1>,<file2>,..,<fileN>
If you give the directory in your filelist they are also created on the server side.