7 ms·
Netcat: $ nc -l 4242 > dest And then on the sending end: $ nc hostname 4242 < file_to_send This works great when you just need to get a file of any
by ashton314 6y ago
Netcat:
$ nc -l 4242 > dest
And then on the sending end:
$ nc hostname 4242 < file_to_send
This works great when you just need to get a file of any size from one machine to another and you’re both on the same network. Are used this a lot at one of my offices to schlep the files around between a few of the machines we had.
- unilynx 6y agoThis is especially fun when combined with piping through tar, and adding pv in the mix for a transfer speed "progress" bar. Fastest way to transfer a collection of files on a local network and doesn't require temporary storage for the archive
- enriquto 6y agopiping through tar is my "power move" when I want to steer a new recruit. I just do it casually in front of them... depending on whether they are awed or horrified by that, they'll get more hacky or more formal work.
- parliament32 6y agoYou can also pipe through gpg if you want encryption along the way!
- ahsima1 6y agoAnd through gzip/zstd/etc if you want compression!
- enriquto 6y agothat's what the -C option to ssh is for
- cellularmitosis 6y agolzop if you gotta go fast :)
- namibj 6y agozstd easily outruns a gigabit link on most somewhat-compressible data.
- 3np 6y agoAnd through tac if you want it in reverse! (...And my axe!)
- labawi 6y agoNote that gpg compresses by default. Which is thy it's so slow. You may wish to use lzop or zstd but also disable gpg's compression. I usually use ssh (e.g. ssh -L 3333:localhost:3333) and avoid gpg, though I may use lzop depending on link and CPU speed.
- kortex 6y agoWhat's an example of the syntax of this? I remember seeing a graybeard do something like this to huck some files to another machine.
- waterhouse 6y agoParaphrased from a real example: tar cf - files morefiles | ssh user@dest "tar xf -" If you want to insert, say, compression: tar cf - files morefiles | zstd | ssh user@dest "zstd -d | tar xf -"
- ashton314 6y agoNice. This to me is a great testament of the power of the Unix philosophy: small orthogonal tools that operate on streams of text.
- Matthias247 6y agoand if you are not worried about corruption. You might at least want to run a checksum on both ends and compare them.
- myself248 6y agoNah, unix nerds don't care about data corruption. That's the responsibility of some other layer, so by definition we're not in trouble if the whole thing blows up by our own negligence. Checkmate, rsync.
- gpm 6y agoNetcat is tcp is "reliable" and has checksums for each packet, as long as the length is right you can be reasonably assured that the file transferred correctly. Not that extra checksums are a bad idea...
- Matthias247 6y agoTCP indeed has checksums! But they are known not to offer ultimate protection. I had to deal with hosts corrupting TCP streams due to bad hardware before. Which was luckily detected by higher level checksums.
- kortex 6y agoIs there a streamlike tool (a la sed, gzip, etc) that applies forward error correction? I've been looking for such a thing but can't find one that scratches the itch.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- rags2riches 6y agoI've done that many times, often in combination with tar and pv as mentioned in another reply. But I prefer to do the listening on the sending side. Feels more like serving than shoving I guess. Also, I remember needing a -q flag on one of the ends for graceful shutdowns.