4 ms·
nc is also awesome for quick and dirty file/directory transfer over the wire: host1 (receiving): nc -l 6123 > tar xfz - host2 (sending ): tar cfz - direct
by yan 18y ago
nc is also awesome for quick and dirty file/directory transfer over the wire:
host1 (receiving): nc -l 6123 > tar xfz -
host2 (sending ): tar cfz - directory/ | nc host2 6123
- alnayyir 18y agoyou know, it's cool that you do that (quite neat in fact), but why is this better than scp'ing something, pray tell?
- meredydd 18y agoMy favourite two reasons for using it: 1. I often tend to use it when I want to pipe the output into a command. If it's a big transfer, I don't really want to have to stream several gigabytes of data onto disk, then off it, then back on again. Restoring a database dump is one example: me@host1$ nc -l -p <port> < db_dump.sql postgres@host2$ nc <host> <port> | psql db-name 2. The other big advantage over scp is that sometimes, your target (deliberately) isn't accessible directly from an SSH login. In the example above, I want to process that data as the 'postgres' user, but there's no way I'm allowing direct logins as that user. 'root' is, of course, the other common example.
- yan 18y agoFirstly, if the two machines are on the same switch this method is noticeably faster than scp'ing something large. The actual main reason though, is that this isn't limited to tarring over a network. What it comes down to, is you can almost seamlessly have a shell pipeline and one of those stages jumps a machine boundary.
- alnayyir 18y agoI see. Gotta love netcat.