开发者

sshd as a transport mechanism

I want to run some command on remote machine, I am not supposed to install any new server. But I am allowed to push one file on the remote machine.

I am trying to use libssh2 to do this, but I am not sure how can i ask sshd server to run the command on my behalf and re-direct STDIN/STDOUT/STDERR in both the direction.

I looked into this example,

http://www.libssh2.org/examples/ssh2.html

But it is ssh terminal emulation.

开发者_如何学JAVA

Anyone has idea on how to achive this using libssh2.

My command is long running and takes input from STDIN and output on STDOUT.


Use the C system call pipe() to redirect your streams. In this instance, you'll want to redirect stdin from your program into the stdin stream of your ssh connection and stdout from that ssh connection into the stdout stream of your program. Here is some 1337 ASCII art I made a while ago demonstrating piping between parent and child processes, which may (or may not) help:

     Parent     
       /\       
      /  \      
     /    \     
  stdin  stdout 
   X        |   
   X        |   
   X        |   
   X        |   
  [0]      [1]  
   X        |   
  [R]      [W]  
  |E|      |R|  
  |A|      |I|  
  |D|      |T|  
  |I|      |I|  
  |N|      |N|  
  [G]      [G]  
   X        /   
   [1]    [0]   
     X    /     
      X  /      
       X/       
       /X       
      /  X      
     /    X     
    /      X    
  stdin stdout  
     \    /     
      \  /      
       \/       
     Child
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜