# How to use Net::SSH for piping?

**URL:** <https://www.ruby-forum.com/t/how-to-use-net-ssh-for-piping/49436>\
**Category:** Ruby\
**Created:** [December 4, 2005, 3:04pm UTC](https://www.ruby-forum.com/t/how-to-use-net-ssh-for-piping/49436 "2005-12-04T15:04:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilmari.heikkinen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@ilmari.heikkinen](https://www.ruby-forum.com/u/ilmari.heikkinen)\
**Post date:** [December 4, 2005, 3:04pm UTC](https://www.ruby-forum.com/t/how-to-use-net-ssh-for-piping/49436/1 "2005-12-04T15:04:57Z")

</div>

Hi, I’ve got a bit of a problem here.

Here’s the setup, I’m proxying a remote command through a unix socket:

1. Started an SSH session to a remote host using Net::SSH
2. Created an UNIXServer and now am accepting connections
3. A new connection arrives
4. Want to pipe the connection’s out to a remote commands’ in, and vice  
versa  
Preferably using a new SSH channel and not a whole session.

E.g. the remote command would be `lame - -`, encoding wav files to mp3,  
and then I would pipe a wav to the proxy and get an mp3 out like this:  
`socat - UNIX-CONNECT:local_socket < my.wav > my.mp3`

What’s the correct way to do the piping to the command and back with  
Net::SSH?

Thanks in advance,  
Ilmari

---

<div class="post-metadata">

**Author:** ![ilmari.heikkinen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@ilmari.heikkinen](https://www.ruby-forum.com/u/ilmari.heikkinen)\
**Post date:** [December 4, 2005, 5:48pm UTC](https://www.ruby-forum.com/t/how-to-use-net-ssh-for-piping/49436/2 "2005-12-04T17:48:25Z")

</div>

> Here’s the setup, I’m proxying a remote command through a unix socket:
> 
> 1. Started an SSH session to a remote host using Net::SSH
> 2. Created an UNIXServer and now am accepting connections
> 3. A new connection arrives
> 4. Want to pipe the connection’s out to a remote commands’ in, and vice  
> versa  
> Preferably using a new SSH channel and not a whole session.

I went with using IO.popen(“ssh #{host}  
#{create\_proxy\_script\_for(filename)}”)  
for now, couldn’t figure out how to do it with Net::SSH  
(session.process.popen3 lacked .close\_write, and trying to send data  
in a blocking fashion with process.open took too much hacking of the  
library internals (and I couldn’t get it working in the end))

Oh well. It’s slow and cumbersome, but at least it works in the  
interim. Need to figure out a better way at some point.
