[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I open one channel and than execute several different commands in libssh?
[Thread Prev] | [Thread Next]
- Subject: Re: How can I open one channel and than execute several different commands in libssh?
- From: Bruno Buzzi Brassesco <bruno.brasesco@xxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Sat, 6 Feb 2021 22:17:14 -0300
- To: libssh@xxxxxxxxxx
Hi, I do not have my notebook now. But you have to open a channel per each command. Regards, Bruno El sáb., 6 de febrero de 2021 22:14, 孙世龙 sunshilong <sunshilong369@xxxxxxxxx> escribió: > Hi,list > > For example i want to open one session and one channel and then > execute severeal different commands. I have InitializeSSHSession and > Initialize SSH channel methods can be seen below. > > void Computer::InitializeSSHSession() > { > ssh_session remoteSSHSession = ssh_new(); > > if ( remoteSSHSession ) > { > QString password = this->GetPassword(); > QString remoteIP = this->GetIP(); > QString userName = this->GetUserNameW(); > > ssh_options_set(remoteSSHSession, SSH_OPTIONS_HOST, > remoteIP.toStdString().c_str()); > ssh_options_set(remoteSSHSession, SSH_OPTIONS_LOG_VERBOSITY, > &sessionVerbosity); > ssh_options_set(remoteSSHSession, SSH_OPTIONS_PORT, &sessionPort); > ssh_options_set(remoteSSHSession, SSH_OPTIONS_USER, > userName.toStdString().c_str()); > > int remoteConnection = ssh_connect(remoteSSHSession); > if ( remoteConnection == SSH_OK ) > { > int authenticateControl = > ssh_userauth_password(remoteSSHSession, NULL, > password.toStdString().c_str()); > if ( authenticateControl == SSH_AUTH_SUCCESS ) > { > InitializeSSHChannel(remoteSSHSession); > } > else > { > remoteSSHSession = NULL; > } > } > else > { > remoteSSHSession = NULL; > } > } > else > { > remoteSSHChannel = NULL; > } > } > > void Computer::InitializeSSHChannel(ssh_session remoteSSHSession) > { > remoteSSHChannel = ssh_channel_new(remoteSSHSession); > > if ( remoteSSHChannel ) > { > int channelControl = ssh_channel_open_session(remoteSSHChannel); > if ( channelControl != SSH_OK ) > { > EventLogger::LogMessage(true, "SSH channel sesssion failed!"); > ssh_channel_free(remoteSSHChannel); > } > } > } > > And in the main, I am initializing session and getting channel like this: > > InitializeSSHSession(); > ssh_channel channel = GetSSHChannel(); > > And then > > int rc = ssh_channel_request_exec(channel, "ls -l"); > > It is okay it is executed correctly but when i want to execute another > command it is not execute, I should return the beginning of process > first initialize session and getting channel again. > > It is not good solution for every command. Is it possible to do that > once initialize session than use it again and again for every command > ? > >
Re: How can I open one channel and than execute several different commands in libssh? | Jakub Jelen <jjelen@xxxxxxxxxx> |
How can I open one channel and than execute several different commands in libssh? | 孙世龙 sunshilong <sunshilong369@xxxxxxxxx> |