Results 1 to 13 of 13
  1. #1
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Redirect the setInputStream and the setOutputStream of the JSch

    Hello my friends

    I am new to java and i need help.
    I use the jsch libraries to create a SHH connection to a remote linux machine. In the next code, given from a tutorial of the JSCH creator, you can see it is implemented shell communication, it is a direct communication from a cmd window. You enter a command from the cmd window and you get aback the results in the cmd window.


    Java Code:
    String user = "username";
    String host = "hostname";
    ession session=jsch.getSession(user, host, 22);
    String passwd = JOptionPane.showInputDialog("Enter password");
    session.setPassword(passwd);
    Channel channel=session.openChannel("shell");
    session.connect(); 
    channel.setInputStream(System.in);
    channel.setOutputStream(System.out);


    How i can redirect the next two lines to jTextField1 and jTextField2. To give an example i want to sen the command from the jTextField1 and to get the results from the jTextField2.

    Java Code:
    channel.setInputStream(System.in);
    channel.setOutputStream(System.out);

    Thank you in advanced

    ki_ha1984

  2. #2
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    Hello

    Any idea ?

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,104
    Rep Power
    6

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    You'd have to build your own inputstream/outputstream that does this. But it seems like you simply want to invoke individual SFTP commands; the JSCH API should have ways to do that. Like this for example:

    JSch - Java Secure Channel - Examples
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    There's the ByteArrayInputStream as well as the ByteArrayOuputStream, so you don't have to build those classes yourself ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,104
    Rep Power
    6

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    Perhaps you're right; my interpretation was that commands were to be 'streamed' directly from the input field to JSCH, since the code seems to be setup like it is a shell accepting input.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    Quote Originally Posted by gimbal2 View Post
    Perhaps you're right; my interpretation was that commands were to be 'streamed' directly from the input field to JSCH, since the code seems to be setup like it is a shell accepting input.
    Normal shell streams are line buffered, but with a bit of fiddling with the model of the JTextField(s) you can even mimic unbuffered behaviour ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    First of all thank you for your answers.
    is there any example how to implement the ByteArrayInputStream and ByteArrayOuputStream with JSCH ?
    Like i see i have to connect those two classes with channel.setInputStream(System.in); channel.setOutputStream(System.out);, from where i can manage the JTextField(s)

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    e.g. for input streams, all you have to do is extend the abstract InputStream and implement the read() method that reads a single byte from somewhere (you should know where to get the byte from); similar with the output streams (see the API docs for the abstract OutputStream class).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    ki_ha1984 is offline Member
    Join Date
    Aug 2011
    Posts
    74
    Rep Power
    0

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    ok i will try it and will give feedback, but i would appreciate it very much if you could post a tutorial, or example of ByteArrayInputStream usages.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    Quote Originally Posted by ki_ha1984 View Post
    ok i will try it and will give feedback, but i would appreciate it very much if you could post a tutorial, or example of ByteArrayInputStream usages.
    Better try the IO tutorial from Sun/Oracle so that you understand what the entire UI framework is all about ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,104
    Rep Power
    6

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    (eh? Read the IO tutorial to understand what the user interface framework is about?)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    Quote Originally Posted by gimbal2 View Post
    (eh? Read the IO tutorial to understand what the user interface framework is about?)
    This is so silly: I wanted to type IO again, but my fingers were too lazy and didn't move to the right far enough, so it came out as UI ...

    kind regards,

    Hia ;-)
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,104
    Rep Power
    6

    Default Re: Redirect the setInputStream and the setOutputStream of the JSch

    LOL! I see now. That is just hilarious.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. JSch 0.1.48
    By java software in forum Java Software
    Replies: 0
    Last Post: 05-15-2012, 06:43 PM
  2. Reg JSCH
    By Vinod Mukundan in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2011, 08:25 AM
  3. JSch 0.1.38
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-24-2008, 06:50 PM
  4. JSch 0.1.36
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-30-2007, 06:05 PM
  5. JSch 0.1.33
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-11-2007, 09:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •