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 6577301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:37:05+00:00 2026-05-25T15:37:05+00:00

I am new to SSH and JSch. When I connect from my client to

  • 0

I am new to SSH and JSch. When I connect from my client to the server I want to do two tasks:

  1. Upload a file (using ChannelSFTP)
  2. Perform commands, like creating a directory, and searching through a MySQL database

At the moment I am using two separate shell logins to perform each task (actually I haven’t started programming the MySQL queries yet).

For the upload the relevant code is

session.connect();

Channel channel=session.openChannel("sftp");
channel.connect();
ChannelSftp c=(ChannelSftp)channel;
c.put(source, destination);

And for the command I have

String command = "ls -l";//just an example 
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command);

Should I disconnect the session after the first channel and then open the second channel? Or close the session entirely and open a new session? As I said, I’m new to this.

  • 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-05-25T15:37:06+00:00Added an answer on May 25, 2026 at 3:37 pm

    One SSH session can support any number of channels – both in parallel and sequentially. (There is some theoretical limit in the channel identifier size, but you won’t hit it in practice.) This is also valid for JSch. This saves redoing the costly key exchange operations.

    So, there is normally no need to close the session and reconnect before opening a new channel. The only reason I can think about would be when you need to login with different credentials for both actions.

    To safe some memory, you might want to close the SFTP channel before opening the exec channel, though.

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

Sidebar

Related Questions

I'm new to SSH. How to copy a .gz file from one server to
i am using jsch to get ssh output from a local ssh server. When
Actually very new user to bash.and I am logging into server using ssh sam@xyz.com
use Control::CLI; $cli = new Control::CLI('SSH'); $cli->connect(Host=>'10.10.10.10',Username=>'user',Password=>'pwd'); $cli->waitfor('>'); $cli->print('Show XXXXXXXXXXXXXXXXXXXX| grep Active'); @f=$cli->waitfor('>'); print
I am using Net::SSH::Perl to execute a command on a remote server as follows:
I'm writing the servers list part of a new iOS SSH client, and I
I'm only new to using SSH, but when I log in I end up
I'm new to unix. I need to copy file over ssh. This is what
I just set up a new LAMP server. I can connect to mysql through
HI all, i want to connect to remote Linux machine and get response from

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.