Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:40:22+00:00 2026-06-18T04:40:22+00:00

I connected to a unix server through ssh and tried to execute a ls

  • 0

I connected to a unix server through ssh and tried to execute a “ls” command and obtain it’s output. The code is like this

SessionChannelClient session = client.openSessionChannel();
       session.startShell();
       String cmd = "ls -l";
       session.executeCommand(cmd);           
       ChannelInputStream in = session.getInputStream();
       ChannelOutputStream out = session.getOutputStream();
       IOStreamConnector input = new IOStreamConnector(System.in, session.getOutputStream());
       IOStreamConnector output = new IOStreamConnector(session.getInputStream(), System.out);

After running I was not getting any output in log file. What I found is that the channel request is failing as shown

1019 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol – Channel request succeeded
1020 [main] INFO com.sshtools.j2ssh.session.SessionChannelClient – Requesting command execution
1021 [main] INFO com.sshtools.j2ssh.session.SessionChannelClient – Command is ls -l
1021 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol – Sending exec request for the session channel
1021 [main] INFO com.sshtools.j2ssh.transport.TransportProtocolCommon – Sending SSH_MSG_CHANNEL_REQUEST
1021 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol – Waiting for channel request reply
1032 [Transport protocol 1] INFO com.sshtools.j2ssh.transport.TransportProtocolCommon – Received SSH_MSG_CHANNEL_EXTENDED_DATA
1033 [ssh-connection 1] DEBUG com.sshtools.j2ssh.transport.Service – Routing SSH_MSG_CHANNEL_EXTENDED_DATA
1033 [ssh-connection 1] DEBUG com.sshtools.j2ssh.transport.Service – Finished processing SSH_MSG_CHANNEL_EXTENDED_DATA
1075 [Transport protocol 1] INFO com.sshtools.j2ssh.transport.TransportProtocolCommon – Received SSH_MSG_CHANNEL_FAILURE
1075 [main] INFO com.sshtools.j2ssh.connection.ConnectionProtocol – Channel request failed

Why is this happening ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:40:23+00:00Added an answer on June 18, 2026 at 4:40 am

    You can use startShell or executeCommand, but not both.

    executeCommand is only intended to invoke a particular shell of your choosing, e.g. /bin/bash. In most cases you can just use startShell to start the default shell.

    This is all you need to execute the command you provided:

    final String cmd = "ls -l" + '\n';       
    session.startShell();
    session.getOutputStream().write(cmd.getBytes());
    

    Or, alternatively, using executeCommand:

    final String cmd = "ls -l";    
    session.executeCommand(String.format("sh -c \"%s\"", cmd));
    

    You can hook up to the stdout & stderr InputStreams in the same manner to see the result of your command. Further, note that a SessionChannelClient can only process one command. You’ll need to instantiate another one to send a second command.

    I suggest you download the J2SSH documentation. Inside you’ll find j2ssh-getting-started.htm which explains the basic operation of the API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to SSH Unix server on button click (code written in
3 ppl (A B C) are connected to a local server (S1) through SSH
I am trying to connect to FTP server through the c# code and I
I have tried EVERY single script/code/method posted on StackOverflow and other sites for this,
When the Wine server launches, it creates a Unix socket through open_master_socket(),all Wine processes
I successfully connected to my database when it was SQL Server 2008 R2. However
I have my pc connected to my television and I use this so I
I have created a repository on Unix server and trying to connect it using
I am creating a simple Unix server written in C++ that simply waits for
The server that Im working on (which is a Unix C multi-threaded non-block socket

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.