3

I would like to pipe data from one machine in the command line to another machine over tcp. I guess I could write a socket server but this must already be implemented. For example I could use it to xz a file and send it over the network to the other side over a specified port, where I could decode and save it:

machine A: strarc -c -d:c:/windows | xz -c -z - | magicsend -p 80 -h 192.168.1.100 machine B: magicreceive -p 80 | xz -d -f - | strarc -x -d:x:/windows

I would like to do this in Linux and/or Windows with open-source tools. So Linux tools that have a[n unofficial] Windows port are preferable. :)

A working example command line is much appreciated.

(Note that on a Linux example I would do cat /vmlinuz instead of strarc, sure it's not quite equivalent. ;) )

3 Answers 3

3

Use netcat. See the "CLIENT/SERVER" section of "man netcat". One machine B:

nc -l 1234 | xz -c > sammy.xz

and on machine A:

cat sammy | nc 192.168.1.100 1234

Note that there can be security implications to leaving ports open in this manner.

As mpy points out, it is more efficient in terms of network bandwidth to compress on the sending side:

xz -c sammy | nc 192.168.1.100 1234

And just save on the receiving side:

nc -l 1234 > sammy.xz
5
  • works quite well, however for some reason this just won't exit for me after sammy is fully read. I think it's netcat. Can it be the implementation I use causing the problem, or is this netcat's design, thus expected? Can I make it somehow exit once sammy is read (EOF), (to arbitrary file sizes and reading times)?
    – n611x007
    Apr 20, 2013 at 6:23
  • @naxa: Hmm.. not clear why this should be. I don't have Windows handy but all of the documentation seems to say that also on Windows the server (B) should exit after the client (A) finishes writing to the pipe. can you post your commands? Sure you are using -l and not -L? Apr 21, 2013 at 18:35
  • 2
    I'm puzzled, why you use xz on receiver's side?! It would be much more efficient, if you compress on sender (machine A): xz -c sammy | nc 192.168.1.100 1234 and inflate on receiver (machine B): nc -l 1234 | xzcat > sammy and IMHO the intention of OP.
    – mpy
    May 5, 2013 at 11:56
  • @mpy: I appended your comment to my answer, thanks. May 5, 2013 at 12:08
  • I appreciate that, already upvoted.
    – mpy
    May 5, 2013 at 12:10
2

Netcat should suit your needs; I don't have the documentation handy so can't be certain, but I think the sending side's command would be [...] | nc -h192.168.1.100 -p80, while the receiving side would use nc -l -p80 | [...].

1

Since you need to remote log in to at least one of the machines (to run either magicsend or magicreceive) could you just use ssh?

ssh clients are easy to come by on Windows (just install cygwin, for example.) ssh servers are also easy to come by, but may be harder to install/configure.

something like this if you are currently on the console of machine A and machine B is remote:

machine A: strarc whatever | xz -c -z - | ssh me@machineB '(xz -d -f - | strarc somethingelse)'

or if you are on the console of machine B and need to remote login to machine A then:

machine B: ssh me@machineA '(strarc whatever | xz -c -z -)' | xz -d -f - | strarc somethingelse

1
  • but may be harder to install/configure out of curiosity did you do this? I did with cygwin and it felt kind of limited and cumbersome.
    – n611x007
    Mar 8, 2016 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .