Here are more examples of transferring files via netcat
(that I've added as aliases/abbreviations to my shell):
nc_openbsd_receive_vanilla nc -l 54321 > _filename_
nc_openbsd_receive_notar nc -l 54321 | gzip -dc | pv > _filename_
nc_openbsd_receive nc -l 54321 | gzip -dc | pv | tar xvf - -C _path_
nc_linux_receive_vanilla nc -l -p 54321 > _filename_
nc_linux_receive_notar nc -l -p 54321 | gzip -dc | pv > _filename_
nc_linux_receive nc -l -p 54321 | gzip -dc | pv | tar cvf - -C _path_
nc_openbsd_send_vanilla nc -N -w 1 192.168.88.241 54321 < _filename_
nc_openbsd_send_notar pv -- _filename_ | gzip -c | nc -N -w 1 192.168.88.241 54321
nc_openbsd_send tar cvf - _file_or_dir_1_ _file_or_dir_2_ | pv | gzip -c | nc -N -w 1 192.168.88.241 54321
nc_linux_send_vanilla nc -q 0 -w 1 192.168.88.240 54321 < _filename_
nc_linux_send_notar pv -- _filename_ | gzip -c | nc -q 0 -w 1 192.168.88.240 54321
nc_linux_send tar cvf - _file_or_dir_1_ _file_or_dir_2_ | pv | gzip -c | nc -q 0 -w 1 192.168.88.240 54321
Vanilla netcat
transfers file(s) but not filename(s), so you have to type filename(s) manually. This can be remedied by a tar
ball which will carry filenames along with files.
Compressing may or may not be beneficial for your setup. With fast network you may lose time compressing-decompressing. With slow network and fast CPU you may gain.
Of gzip
, bzip2
& xz
:
gzip
is the fastest with worst compression,
xz
gives best compression being the slowest,
bzip2
is in between.
-c
& -dc
options work the same for all 3.
gzip -c
/bzip2 -c
/xz -c
to standard output
gzip -d
/bzip2 -d
/xz -d
decompress
pv
visualizes progress
pv --
disambiguates in case your filename starts with a dash
tar c
create
tar x
extract
tar v
verbose
tar f -
standard input or output
tar -C
extract to directory
(tar
doesn't work with --
as it correctly handles filenames starting with a dash and if you type --
, tar
will try to work on a file named --
)
nc -l
listen
nc -p
(Linux
nc
) port
nc -N
(OpenBSD
nc
) close connection upon EOF
nc -q 0
(Linux
nc
) close connection upon EOF
nc -w 1
1 second timeout for establishing connection