This commit is contained in:
Lukas Wurzinger 2025-04-09 01:17:58 +02:00
parent 75cb7fc69a
commit 53f66c53eb
No known key found for this signature in database
2 changed files with 53 additions and 20 deletions

View file

@ -1,5 +1,31 @@
# taft — Totally Adequate File Transfer
A simple wrapper around nc(1) and tar(1).
taft's main focus is speed, so no encryption is involved, to minimize overhead.
If you're looking for a *secure* way to transfer files, go with sftp(1) instead.
*Named after William Howard Taft, [America's greatest president by volume](https://idlewords.com/talks/website_obesity.htm)*.
## Usage
Destination host:
```
$ mkdir destination; cd destination
$ taft receive
```
Source host:
```
$ mkdir source; cd source
$ touch a b c
$ taft send 192.168.178.42 # destination IP address
./
./c
./b
./a
```
The default port is 1337.
It can be changed via the `-p` or `--port` option.

47
taft
View file

@ -22,6 +22,8 @@ port=1337
path=.
tarflags=()
ncflags=()
verbose=false
compress=none
while true; do
case $1 in
(-p | --port)
@ -33,25 +35,11 @@ while true; do
shift 2
;;
(-v | --verbose)
tarflags+=(--verbose)
ncflags+=(-v)
verbose=true
shift
;;
(-c | --compress)
algo=$2
case $algo in
(none)
;;
(xz)
tarflags+=(--xz)
;;
(zstd)
tarflags+=(--zstd)
;;
(*)
error 'invalid compression algorithm'
;;
esac
compress=$2
shift 2
;;
(--)
@ -61,6 +49,25 @@ while true; do
esac
done
if "$verbose"; then
tarflags+=(--verbose --verbose)
ncflags+=(-v)
fi
case $compress in
(none)
;;
(xz)
tarflags+=(--xz)
;;
(zstd)
tarflags+=(--zstd)
;;
(*)
error 'invalid compression algorithm'
;;
esac
if (( $# == 0 )); then
error 'a subcommand is required'
fi
@ -68,7 +75,7 @@ fi
subcommand=$1
case $subcommand in
(send)
(s | send)
shift
if (( $# < 1 )); then
@ -81,16 +88,16 @@ case $subcommand in
dest=$1
tar --create "${tarflags[@]}" -- "$path" | nc -q 1 "${ncflags[@]}" -- "$dest" "$port"
tar --verbose --create "${tarflags[@]}" -- "$path" | nc -q 1 "${ncflags[@]}" -- "$dest" "$port"
;;
(recv | receive)
(r | recv | receive)
shift
if (( $# > 0 )); then
error 'too many arguments'
fi
nc -q 1 -l -p "$port" "${ncflags[@]}" | tar --extract "${tarflags[@]}"
nc -q 1 -l -p "$port" "${ncflags[@]}" | tar --verbose --extract "${tarflags[@]}"
;;
(*)
error 'invalid subcommand'